0

I have an error when I compile my Java code with this annotation:

@Id
@Column(name="\"idClass\"", unique=true, nullable=false, columnDefinition = "serial")
@GeneratedValue(strategy=GenerationType.AUTO)
private Integer idClass;

with <property name="show_sql">true</property> in debug it returns:

Hibernate: select nextval ('hibernate_sequence')

The id column is serial. Any ideas? I've tried to compile with @Generated(GenerationTime.INSERT) but doesn't run. Thanks.

[SOLVED]

My solution is:

     @Id
     @SequenceGenerator(name="IDCLASS_GENERATOR", sequenceName="\"table_idClass_seq\"", allocationSize = 1)
     @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="IDCLASS_GENERATOR")
     @Column(name="\"idClass\"")
django
  • 153
  • 1
  • 5
  • 19

2 Answers2

0

See below code

@Column(name="idClass", unique=true, nullable=false, columnDefinition = "serial")
@Generated(GenerationTime.INSERT)
private Integer idClass;

or you can use

@GeneratedValue(strategy = GenerationType.IDENTITY)
JavaBeigner
  • 608
  • 9
  • 28
  • Thanks but it returns *org.postgresql.util.PSQLException: The column name idClass was not found in this ResultSet*. This exception is fired when is called *session.saveOrUpdate(myObject);* where *myObject* contains all values for the corresponding table except for *idClass* because it is serial and not setted. – django Sep 22 '14 at 08:59
  • Try with @Id @Column(name="\"idClass\"") – JavaBeigner Sep 22 '14 at 09:06
  • Now org.hibernate.id.IdentifierGenerationException: *ids for this class must be manually assigned before calling save():...* @JavaBeigner – django Sep 22 '14 at 09:33
0

Your real problem is case sensitivity, tu use case sensitive column name you must wrap it with backticks.

@Id 
@Column(name="`idClass`") 
@GeneratedValue(strategy = IDENTITY)
private Integer idClass;
Petar Butkovic
  • 1,820
  • 15
  • 14