I am implementing a simple CRUD controller but I have got some issues with JPA/Hibernate and Spring Data JPA framework. Repositories seem to work fine unless I use an entity mapped to a table with a name that contains an underscore.
ProfileItem.java
@Entity @Table(name = "PROFILE_ITEM") @SequenceGenerator(name = "SequenceGenerator", sequenceName = "SEQ_PROFILE_ITEM", initialValue = 1, allocationSize = 1) public class ProfileItem implements Serializable { private static final long serialVersionUID = ApplicationConst.DEFAULT_SERIAL_VERSION_UID; @Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SequenceGenerator") private Long id; @Column(name = "USER_ID") private String uid; private String context; private String application; @Column(name = "CREATED_ON") @Temporal(value = TemporalType.DATE) private Date createdOn; @Column(name = "MODIFIED_ON") @Temporal(value = TemporalType.DATE) private Date modifiedOn; private Long version; @OneToMany(mappedBy = "profile", fetch = FetchType.EAGER, cascade = CascadeType.ALL) private List<ProfileItemData> profileItemData; // getters and setters ... } ProfileItemDao.java
public interface ProfileItemDao extends Repository<ProfileItem, Long> { public ProfileItem findById(Long id); } When I try to invoke the interface method I get the following exception:
Caused by: java.sql.SQLSyntaxErrorException: ORA-00904: "PROFILEITE0_"."USER_ID": invalid identifier Using
@Query("SELECT p FROM ProfileItem p WHERE p.id = :id") public ProfileItem findById(@Param("id") Long id); did not help either.
I have recreated the scenario for a table with a single word name and everything worked alright. It seems like Spring is trying to force some naming strategy.
Is there any way abandon it? Every solution I have found was tied to Spring Boot which I do not use.
Thank you in advance. I can provide some additional info if necessary.
PROFILE_ITEMhas a columnUSER_ID?CrudRepositoryremove yourfindByIdmethod and usefindOne. Also is there REALLY a column namedUSER_IDmake sure the casing matches!