• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Using hibernate delete

 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
when making use of session.delete(obj) inorder to delete an object, it seems like all the not null fields have to be set on the object to be deleted. Is it not enough if we just set the id?
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Should be. Can you give us more details?
 
Priya Venkatesan
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry for not being clear.
If I had the following mapping...
<property name="cost" type="big_decimal" precision="8" scale="2" not-null="true" lazy="false"/>
<property name="size" type="int" column="size" length="10" not-null="true" lazy="false"/>

then while trying to delete the object with only "id" value set, complains that the not-null values for cost and size has to be set...

org.hibernate.PropertyValueException
Original message: not-null property references a null or transient value:

Not sure why hibernate needs all the not null properties to be set just to delete. It would be nice if it can perform the delete function when I pass in the object id.

One more question on this...
If I had a hibernate mapping which uses table per subclass strategy, something like:

<class name="com.abc.A" table="ABC" lazy="false">
.....
<joined-subclass name="com.abc.MyA" extends="com.abc.A" table="XYZ" lazy="false">
<key column = "ID"/>
<property name="branchNumber" type="string" column="branchNumber" length="20" not-null="false" lazy="false"/>
</joined-subclass>
</class>

and wrote a "delete" HQL to delete the MyA object, then it seems like hibernate would not delete records from both ABC and XYZ table. This seems to be working when I use session.delete(MyA). The error that I get while using the delete HQL is...

<Exception occurred
<com.chordiant.service.ServiceException: Unexpected Exception deleting a browse record: could not insert/select ids for bulk delete

Original exception: org.hibernate.exception.SQLGrammarException

Original message: could not insert/select ids for bulk delete

Original exception stack trace:

org.hibernate.exception.SQLGrammarException: could not insert/select ids for bulk delete

at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)

at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)

Any thoughts on these?




If I had an object with not-null attribute set to true, then while trying
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For the first question, Hibernate does those validations before even going to the database. Hence if you have something wrong, like a not-null value set, Hibernate can report it back before doing a database hit. Not sure why they didn't check in delete, that if it has an ID let it not go through that validation, but I think they might have made the whole thing generic where it doesn't look at what you are performing, just always validating.

You might need to retrieve the object first, like through load, get a proxy object, no hit to the database, then call delete using the proxy object.

Mark
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic