-->
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: Hibernate mapping problem
PostPosted: Thu Mar 27, 2008 9:15 am 
Newbie

Joined: Thu Mar 27, 2008 9:07 am
Posts: 1
Hibernate version: 3

Hi,

I am new to hibernate and I used the search function and google before I post here. I have a simple java class and I need to map it with hibernate-mapping files.

This is my class:


Code:
public class Berichtbuffer {
   private Long idBerichtbuffer;
   private Stuurgegevens stuurgegevens;
   private String bericht;
   private BerichtStatus berichtStatus;
   private String zendendCode;
   private String ontvangendCode;
   private Set<Foutbuffer> foutmeldingen = new HashSet<Foutbuffer>();
   **
      getters + setters
   **
}


My problem is with the 'private Stuurgegevens stuurgegevens'.

My mapping file looks like this:

Code:
<hibernate-mapping>
<class name="nl.messagedesign.stufkletser.hibernate.Berichtbuffer" table="berichtbuffer">
   <id name="idBerichtbuffer" type="long" column="idBerichtbuffer" >
      <generator class="native"/>
   </id>
   <component name="Stuurgegevens">
      <property name="zenderGebruiker" access="field"/>
      <property name="ontvangerGebruiker" access="field"/>
      <property name="referentienummer" access="field"/>
   </component>
   <property name="bericht"/>
   <property name="berichtStatus"/>
   <property name="zendendCode"/>
   <property name="ontvangendCode"/>
</class>
</hibernate-mapping>


'Stuurgegevens' class doesnt have an empty constructor, thats the exception that I'm getting --> No default constructor for entity: nl.messagedesign.stufkletser.werkenMetStUF.Stuurgegevens

Stuurgegevens is a class that consists of several fields. I need those fields in my 'Berichtbuffer' table, but I don't know how to map this with hibernate.

Do I have to copy all my fields in 'Stuurgegevens' to my 'Berichtbuffer' class or can I make clear to hibernate to use the fields in that class?

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 27, 2008 9:54 am 
Regular
Regular

Joined: Mon Aug 06, 2007 10:49 am
Posts: 67
Location: Banska Bystrica, Slovakia
hibernate needs for every class mapped or component class empty constructor, so that it could create an instance of that class.

component properties are mapped like any other properties of main class, u just group them by component tag , that is,

so u dont need to copy them to Berichtbuffer in your case, just create empty constructor for class Stuurgegevens


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 28, 2008 12:57 pm 
Newbie

Joined: Tue Aug 03, 2004 10:31 am
Posts: 7
As ferozz say, I agree that every class mapped or component class empty constructor

You can use <component> mapping for map Stuurgegevens class in your 'Berichtbuffer' table. Thats alows you to map two clases into one table, provided you have a one-to-one relationship.

see: http://www.hibernate.org/hib_docs/reference/en/html/mapping.html#mapping-declaration-component

good luck


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.