Proper method to insert to a table column with default value using ORM

I have a table column that is create_date with a datatype Timestamp. This column has a defalt value of Now() to generate the time of the insert.

When trying to insert a record using ORM i get the following error:

org.orm.PersistentException: org.hibernate.PropertyValueException: not-null property references a null or transient value: com.asentria.orm.Users.create_date
at org.orm.PersistentSession.saveOrUpdate(PersistentSession.java:643)
at org.orm.PersistentManager.saveObject(PersistentManager.java:274)
at com.asentria.orm.impl.UsersDAOImpl.save(UsersDAOImpl.java:263)
at Test.main(Test.java:17)

I can see that Hibernate does not want to allow the object to persist with a null value for the create_date attribute. What is the proper method to allow this to persist and allow the database to make the insert?

The output from ORM is using annotations and I have noticed that I can use updatable=false, nullable=false to make this work properly, but I don’t know how to make VisualParadigm set this variable on the Column attribute.

The output i get is:
@Column(name=“create_date”, nullable=false, length=35)
private java.sql.Timestamp create_date;

The desired output is:
@Column(name=“create_date”,insertable=false,updatable=false, nullable=false, length=35)
private java.sql.Timestamp create_date;

Can anyone say how this is set up?

Hello Kbromberger,

Thank you for your message. For your case you should specify Generated as Insert in Column Specification Dialog (see attached pic). By specify generated as insert, it will retrieve the default value when insert to database. Feel free to contact me if you need any help.

Best regards,
Rain

insert.png

Hi Rain,

Thank you for the response. However, the behavior I am seeing is that setting the generated value to “Insert” does not have the intended effect on the annotations being generated. Which causes the error. If you use XML config output rather than annotations the insert works as expected.
Best,
Ken

Hello Ken,

Would you mind send me your project to have a look? If you don’t want to publish your project file in this forum, you can send it to support-team@visual-paradigm.com. Please include this forum link in your email so that we can associate your case. Look forward to hear from you.

Best regards,
Rain