-->
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.  [ 1 post ] 
Author Message
 Post subject: UserType-Annotation returns null in combination w/ ManyToOne
PostPosted: Tue Jul 05, 2011 3:12 am 
Newbie

Joined: Tue Jul 05, 2011 2:35 am
Posts: 1
Hi Forum,

I run the following environment:

- Virgo Tomcat Server 3.0.0.M5 (OSGi/Spring environment providing the possibility to deploy "OSGified" WARs)
- OSGi enabled versions of Hibernate 3.3.2.GA with Hibernate Annotations 3.4.0.A-A from the SpringSource Enterprise Bundle Repository (newest available there)
- PostgreSQL 9.0.3 (with JDBC4-Driver for PostgreSQL 8.3 as it was the newest OSGi bundle i could found from the SpringSource Enterprise Bundle Repository)

As some of my mapping classes contain fields for storing JSON objects, I use a usertype similar to the one described here for mapping. This works quite well until I add a @ManyToOne annotation to the mapping class. Then i still can persist objects and the JSON ends up correctly in the database, but when querying for the objects, the JSON fields return null. The mapping works well when I use XML mapping instead of annotations for that class.

Some code snippets:

Working mapping:

Code:
@Entity
@Table(name="mappingclass1")
@SequenceGenerator(name="id_mapping1_seq", sequenceName="id_mapping1_seq", allocationSize=1)
public class MappingClass1 {

   protected long id;
   protected JSONObject json;
   protected String description;
   
   @Id
   @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="id_mapping1_seq")
   public long getId() {
      return this.id;
   }
   public void setId(long id) {
      this.id = id;
   }
   
   @Basic
   @Column
   @Type(type = "x.x.x.usertypes.JSONObjectUserType")
   public JSONObject getJson() {
      return json;
   }
   public void setJson(JSONObject json) {
      this.json = json;
   }
   
   public String getDescription() {
      return description;
   }
   public void setDescription(String description) {
      this.description = description;
   }
}


Mapping with the described problem:

Code:
@Entity
@Table(name="mappingclass2")
@SequenceGenerator(name="id_mapping2_seq", sequenceName="id_mapping2_seq", allocationSize=1)
public class MappingClass2 {
   
   protected long id;
   protected JSONObject json;
   protected MappingClass3 mapping3;   
   
   @Id
   @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="id_mapping2_seq")
   public long getId() {
      return this.id;
   }
   public void setId(long id) {
      this.id = id;
   }
   
   @Basic
   @Column
   @Type(type = "x.x.x.usertypes.JSONObjectUserType")
   public JSONObject getJson() {
      return json;
   }
   public void setJson(JSONObject json) {
      this.json = json;
   }

   @ManyToOne(cascade = CascadeType.ALL)
   @JoinColumn(name="mapping3_id")
   public MappingClass3 getMapping3() {
      return wbcategory;
   }
   public void setMapping3(MappingClass3 mapping3) {
      this.mapping3 = mapping3;
   }
}


Working XML mapping for the above class:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="x.x.x.types">
   <class name="MappingClass2" table="mappingclass2" lazy="false">
   <id name="id" column="id">
      <generator class="sequence">
         <param name="sequence">id_mapping2_seq</param>
      </generator>   
   </id>
   <property name="json" type="x.x.x.usertypes.JSONObjectUserType" />
   <many-to-one name="mapping3" class="MappingClass3" column="mapping3_id" />
   </class>
</hibernate-mapping>


Currently I've got no idea where to look for problems next. Can it be some OSGi related class-loading problem, i.e. some classes not visible to Hibernate? Or is this a known bug of one of the not-so-new versions of the libraries I'm using, so I have to jump into the cold water and create my own OSGi enabled bundles of newer versions? Or am I just missing some difference between the mapping of the XML and the annotated version?

Thanks for any help

Carsten


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

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.