-->
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: Persistenz von inneren Klassen
PostPosted: Tue Jan 19, 2010 5:34 am 
Newbie

Joined: Tue Jan 19, 2010 5:13 am
Posts: 4
Hallo,

ich kriege das Mapping von einer inneren Klasse nicht gelöst.

Mein Beispiel

******************************
Class A mit innerer Class B
*******************************

package rw.hibernate.inheritance;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.OneToMany;

@Entity
public class A {
@Id
@Column(name="a_id")
private long id;
private String a_name;
@Embedded
private B b;
public A(){b=new B();}
public long getId() {return id;}
public void setId(long id) {this.id = id;}
public String getA_name() {return a_name;}
public void setA_name(String aName) {a_name = aName;}
public B getB() {return b;}
public void setB(B b) {this.b = b;}
public void setB_name(String bName) { b.setB_name(bName); }
public String getB_name() {return b.getB_name();}


@Embeddable
static class B
{private String b_name;
public String getB_name() {return b_name;}
public void setB_name(String bName) {b_name = bName;}
}}
--------------------------------------------------------------------
*****************
Test
*****************
public static void main(String[] args) {
Transaction tx = null;
try{
Session session = HibernateUtil.getSession();
tx=session.beginTransaction();
a.setId(100l);
a.setA_name("Test A");
a.setB_name("Test B");
session.save(a);
System.out.println("Done");
tx.commit();
session.flush();
session.close();}
catch(Exception e){System.out.println(e.getMessage());}}


---------------------------------------------------------------------------------

Darauf erhalte ich flg.Fehlermeldung :
Hibernate: insert into A (a_name, b_name, a_id) values (?, ?, ?)
Could not execute JDBC batch update
---------------------------------------------------------
*******************
Auszug aus der hibernate.cfg.xml
************************************
<mapping class="rw.hibernate.inheritance.A"/>
<mapping class="rw.hibernate.inheritance.A$B"/>
-------------------------------------------------------

Ich vermute mal es wird daran liegen das b_name nicht zur Verfügung steht.
auch ein save(a.getB()) hilft nicht weiter.
Eine Diskussion ob man innere Klassen so verwendet ist im Moment sinnfrei, da die Klassen
so von JAXB erstellt werden.
Es geht nur um die Frage wie kann ich innere Klassen durch Annotations mappen.

Hat jemand einen Tipp?

mfg. Roland


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.