2

Dears,

I have multiple tables and I need to add extra columns in each, I added them entity classes but hibernate stilldoesn't create them, I even tried to use the added columns in hql queries but it gives an error that property doesn't exist.

Columns I want to add:

@Column (name = "CREATED_BY")
    private String createdBy;

    private String active;

I retrieved an object and tried to print the value of active. it said this propery doesn't exist.

#{obj.active}
Kukeltje
  • 12,223
  • 4
  • 24
  • 47
Code des
  • 31
  • 3
  • It is already answered, please refer this link : https://stackoverflow.com/questions/15978368/hibernate-hbm2ddl-auto-update-doesnt-update-column-definitions-in-mysql – srinivas Jul 04 '18 at 07:49
  • @srinivas it's not, the link you gave says that having "update" would solve the issue but it's not. I mean I have the "update" but still the columns are not added – Code des Jul 04 '18 at 08:01
  • @Code des can you show us the annotations of the entity class itself? I mean annotations such as _@Table_ – Isaac_Zhu Jul 04 '18 at 23:52
  • Hei, do you find a solution? :) – Padi Apr 10 '20 at 14:10

2 Answers2

1

@Code des It just hit me. Did you happen to forget the setters for the new fields? If that is the case, try to add the setters for the fields (maybe also getters). Make those private if you don't want other business logic to change the fields. Also, you mentioned you're using Hibernate 3 and there's no @CreationTimeStamp(I haven't got time to check if that's true), then I wonder how come you didn't get compile error when using an unexisting annotation??

Isaac_Zhu
  • 105
  • 10
0

You have not added hibernate property to active variable

@Column (name = "active")

private String active;

  • 1
    I don't think you need to add the annotation there. `@Column` annotation is needed only when you want to change default setting, say, column name and length. – Isaac_Zhu Jul 04 '18 at 11:02
  • hi..Isaac_Zhu, but how hibernate/jpa can map/create active column in database without @Column annotation. Because of this it gives error(property doesn't exist). There is no column(active) found in database. – Gaurav Shakya Jul 04 '18 at 11:37
  • 1
    JPA (Java Pesistence API, Hibernate implements JPA) will create a default definition of the table column for each field according to the field name and the type, unless the field is explicitly marked with @Transient. In this case, it will be same as if you put @Column(name=“active”). – Isaac_Zhu Jul 04 '18 at 12:51
  • @Isaac_Zhu can the JPA be the reason why creationtimestamp annotation doesn't work ? – Code des Jul 05 '18 at 04:38
  • @Codedes are you asking something different? Do you mind posting a more complete version of your entity? `@CreationTimestamp` works if configured correctly, also it's good to set the `updatable = false` for the corresponding field so it won't be accidentally updated. – Isaac_Zhu Jul 05 '18 at 06:23
  • @Isaac_Zhu for creationtimestamo, I have hibernate 3 and seems it's not on that version – Code des Jul 10 '18 at 05:29