[hibernate-issues] [Hibernate-JIRA] Commented: (ANN-749) Generated Annotation can not generate Date automatically
Jim Cushing (JIRA)
noreply at atlassian.com
Tue Jul 29 10:50:47 EDT 2008
[ http://opensource.atlassian.com/projects/hibernate/browse/ANN-749?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_30754 ]
Jim Cushing commented on ANN-749:
---------------------------------
You're misunderstanding what @Generated means. This indicates the value is generated by the database. When you include this annotation, Hibernate will select the value from the database after an insert and/or update (depending on your GenerationTime), such that the in-memory entity has the proper value.
For example, used use @Generated if your database supports an auto-increment/identity column for primary keys, or if you've got a value that's updated via a trigger.
> Generated Annotation can not generate Date automatically
> --------------------------------------------------------
>
> Key: ANN-749
> URL: http://opensource.atlassian.com/projects/hibernate/browse/ANN-749
> Project: Hibernate Annotations
> Issue Type: Bug
> Affects Versions: 3.3.1.GA, 3.4.0.CR1
> Environment: OS: Windows XP
> DB: HSQL
> Reporter: yuanqingfei
>
> @Before
> public void setup() {
> order = new Order();
> // enter all required fields
> order.setName("order1");
> order = orderDAO.save(order); //Hibernate should generate a timestamp here
> }
> @Test
> public void testSave() {
> assertTrue(orderDAO.exists(order.getId()));
> System.out.println(order.getCreateTime()); //here should get a date.
> }
> Annotation part in Order:
> @Temporal(TemporalType.TIMESTAMP)
> @Column(insertable = false,updatable=false)
> @org.hibernate.annotations.Generated(org.hibernate.annotations.GenerationTime.INSERT)
> private Date createTime;
> Save part in OrderDAO.
> @SuppressWarnings("unchecked")
> public T save(T object) {
> return (T) super.getHibernateTemplate().merge(object);
> }
> every time, I just only get null.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list