llatrbng
llatrbng

Reputation: 43

Invalid identifier: ORA ORA-00904; Hibernate ignoring Intellij-IDEA generated @Column (name="") annotation on getter

I have a Spring boot application (2.1.5) using Hibernate (5.1), as my JPA provider, accessing an Oracle 11.2.0.4 DB, with Hibernate Dialect Oracle10gDialect

I have created a repo like this

@Repository
public interface VehStoRepository extends CrudRepository<VehStoEntity, Long>
{
}

and my Entity is as follows

@Entity @Table(name = "VEH_STO", schema = "MySchema") 
public class  VehStoEntity
{
  @Id
  private long eventNo;
  private Long stoType;

  Basic @Column(name = "STO_TYPE", nullable = true, precision = 0) 
  public Long getStoType()
  {
    return stoType;
  }

  public void setStoType(Long stoType)
  {
    this.stoType = stoType;
  }
... 
}

With many other fields etc, that I have excluded for brevity. I had the persistence mapping generated by Intellj Idea.

Now, when calling vehStoRepository.findAll();
I get the following error:

Caused by: org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet

...

Caused by: java.sql.SQLSyntaxErrorException: ORA-00904: "VEHSTOENT0_"."STOTYPE": invalid identifier

My SQL statement as the logs show it is:

Hibernate: select vehstoent0_.stoType as stoType25_0_ from MYSCHEMA.VEH_STO vehstoent0_

My question is: does hibernate actually add ent0 to the entity name or is this just weird logging, or is this the cause of the error? Is this because I have not generated an ORM mapping schema for all tables, just for the one I needed? What am I doing wrong?

Upvotes: 0

Views: 1097

Answers (1)

llatrbng
llatrbng

Reputation: 43

It was this:

My sql table was a view, so I assume that's why Intellij didn't create an @Id annotation. So i created the @Id manually over the field, but Intellij had the @Column (name="")

annotation on the getter, which Hibernate then ignored.

I have solved the problem by moving all annotations to the fields instead.

Upvotes: 0

Related Questions