-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Inheritance problem: Error while persisting object
PostPosted: Wed Apr 05, 2006 2:45 pm 
Newbie

Joined: Mon Nov 08, 2004 4:05 am
Posts: 6
Hibernate version: 3.1

Friends,
I am sorry if this is a very trivial and oft-repeated problem. I did look around a little and could not find anything very helpful. Pl help.

I am running into a problem when trying to save an entity extending from an abstract base class which simply holds the primary ID (common to all entities). Here is my code :

Parent Class
Code:
public abstract class BaseEntity<T extends java.io.Serializable> {
   private T id;
   
   public T getId() {return this.id;}
   public void setId(T id) {this.id = id;}
}


Child Class
Code:
public class Address<Integer> extends BaseEntity {
   String addressText, city;

    public String getAddressText() {
      return addressText;
   }
   public void setAddressText(String addressText) {
      this.addressText = addressText;
   }
   public String getCity() {
      return city;
   }
   public void setCity(String city) {
      this.city = city;
   }
}


There may be other implementations of the BaseEntity as well.

The mapping file for Address (using the table-per-concrete-class strategy) :

Code:
<hibernate-mapping package="com.vca.paws.datamodel" >
  <class name="Address" table="Address" polymorphism="implicit">
   <id name="id" type="integer" unsaved-value="null" >
      <column name="id" not-null="true"/>
       <generator class="increment"/>
      </id>
      
           <property column="addressText" name="addressText" type="string" not-null="true"/>
      <property column="city" name="city" type="string" not-null="true"/>
</hibernate-mapping>


Now, when I try to save or update an Address entity, I get the below error :

Code:
Could not execute JDBC batch update; bad SQL grammar [update Address set addressText=?, city=? where id=?]; nested exception is java.sql.BatchUpdateException: No value specified for parameter


Could you pl point me where I am going wrong ?

Anyinputs would be most welcome !

Thanks.[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 05, 2006 5:37 pm 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
Hibernate tries to update instead of saving your new entry. So it assumes that the id is specified.

You may try to remove the
unsaved-value="null" from your id mapping.

Regards Sebastian

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


Top
 Profile  
 
 Post subject: Bad bad..sorry for this
PostPosted: Thu Apr 06, 2006 3:09 pm 
Newbie

Joined: Mon Nov 08, 2004 4:05 am
Posts: 6
I am sorry for having troubled you all on this.. this was a problem with the way I had used the generic type in my child class. It should have been :

Code:
public class ChildClass extends Parent<Integer> {..}


It works like a charm now !

Thanks , and sorry again for the bad post.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.