Author | Message |
---|---|
mkhalil
Posts: 8
|
Posted 19:05 Nov 17, 2010 |
Is there anyway to get "LAST_INSERT_ID" in Hibernate? |
cysun
Posts: 2935
|
Posted 20:42 Nov 17, 2010 |
Not sure what you mean. When you save a new object using Hibernate, before saveOrUpdate(), the ID field of the object is null, and after saveOrUpdate(), the ID field will set with the generated ID. |
mkhalil
Posts: 8
|
Posted 21:11 Nov 17, 2010 |
Right, So what if I want to get the new genereted ID? I can do that by executing this query: "select max(id) from File" right after saveOrUpdat(), but I think that is not an efficient way, especially when the table is used by many users. |
cysun
Posts: 2935
|
Posted 21:15 Nov 17, 2010 |
You can use getId() to get the ID. |