-->
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.  [ 4 posts ] 
Author Message
 Post subject: Eine einfache Beziehung zwischen zwei Tabellen abbilden?
PostPosted: Sun Nov 13, 2005 3:10 pm 
Newbie

Joined: Sun Nov 13, 2005 2:52 pm
Posts: 2
Hallo,

seit kurzem befasse ich mich mit Hibernate nur habe ich es leider trotz guter Doku nicht hinbekommen, dass Hibernate das so macht wie ich es mir vorstelle.

Tabelle mitarbeiter:
user_id int4 NOT NULL,
vorname varchar(100) NOT NULL,
nachname varchar(100) NOT NULL,
geb_datum date NOT NULL,
telefon_geschaeft varchar(50),
team_id int4 NOT NULL,
gehalt float8 DEFAULT 0,
urlaubsanspruch float8,
CONSTRAINT mitarbeiter_pk PRIMARY KEY (user_id)


Tabelle urlaub:
user_id int4,
von date NOT NULL,
bis date NOT NULL,
status varchar(255),
CONSTRAINT urlaub_fk FOREIGNKEY (user_id)
REFERENCES hrportal.mitarbeiter (user_id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE CASCADE


Dann habe ich entsprechende POJOs geschrieben, wobei in der Klasse MitarbeiterData es ein Attribut vom Typ UrlaubData gibt.

Ohne eine Verknüpfung tut das ganze wunderbar.
Aber sobald ich dann möchte das Hibernate das UrlaubData Objekt entsprechend den Daten in der Tabelle urlaub füllt gehts schief.

Ich habe jetzt schon verschiedene Möglichkeiten ausprobiert, aber funktioniert hats bisher noch nicht.


Hibernate version: 3.1rc1

Mapping documents:
Quote:
hibernate.cfg.xml (verwende für zusätzliche Einstellungen eine hibernate.properties Datei

<hibernate-configuration>
<session-factory>
<mapping resource="Mitarbeiter.hbm.xml"/>
</session-factory>
</hibernate-configuration>


Quote:
Mitarbeiter.hbm.xml

<hibernate-mapping>
<class name="de.hrportal.mitarbeiterverwaltung.db.MitarbeiterData" table="mitarbeiter">
<id name="userId" column="user_id">
<generator class="increment"/>
</id>
<property name="vorname" type="string" not-null="true"/>
<property name="nachname" type="string" not-null="true"/>
<property name="telefonGeschaeft" column="telefon_geschaeft" type="string" not-null="false"/>
<property name="urlaubsanspruch" type="double" not-null="false"/>
<property name="gehalt" type="double" not-null="true"/>
<property name="geburtstag" type="date" column="geb_datum" not-null="true"/>
<joined-subclass name="de.hrportal.urlaubsverwaltung.db.UrlaubData" lazy="true" table="urlaub" entity-name="urlaub">
<key column="user_id"/>
<property name="von" type="date" column="von" not-null="true"/>
<property name="bis" type="date" column="bis" not-null="true"/>
<property name="status" type="string" not-null="false"/>
</joined-subclass>
</class>
</hibernate-mapping>



Full stack trace of any exception that occurs:
Quote:
ERROR property.BasicPropertyAccessor - IllegalArgumentException in class: de.hrportal.mitarbeiterverwaltung.db.MitarbeiterData, getter method of property: userId
Exception in thread "main" java.lang.ExceptionInInitializerError
at de.hrportal.util.HibernateUtil.<clinit>(HibernateUtil.java:29)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at de.hrportal.console.Test.main(Test.java:13)
Caused by: org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of de.hrportal.mitarbeiterverwaltung.db.MitarbeiterData.userId
at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:171)
at org.hibernate.engine.UnsavedValueFactory.getUnsavedIdentifierValue(UnsavedValueFactory.java:44)FATAL util.HibernateUtil - Initiale SessionFactory kann nicht erzeugt werden
org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of de.hrportal.mitarbeiterverwaltung.db.MitarbeiterData.userId
at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:171)
at org.hibernate.engine.UnsavedValueFactory.getUnsavedIdentifierValue(UnsavedValueFactory.java:44)
at org.hibernate.tuple.PropertyFactory.buildIdentifierProperty(PropertyFactory.java:44)
at org.hibernate.tuple.EntityMetamodel.<init>(EntityMetamodel.java:115)
at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:411)
at org.hibernate.persister.entity.JoinedSubclassEntityPersister.<init>(JoinedSubclassEntityPersister.java:90)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:58)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:217)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1145)
at de.hrportal.util.HibernateUtil.<clinit>(HibernateUtil.java:25)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at de.hrportal.console.Test.main(Test.java:13)
Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring class
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:145)
... 12 more

at org.hibernate.tuple.PropertyFactory.buildIdentifierProperty(PropertyFactory.java:44)
at org.hibernate.tuple.EntityMetamodel.<init>(EntityMetamodel.java:115)
at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:411)
at org.hibernate.persister.entity.JoinedSubclassEntityPersister.<init>(JoinedSubclassEntityPersister.java:90)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:58)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:217)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1145)
at de.hrportal.util.HibernateUtil.<clinit>(HibernateUtil.java:25)
... 3 more
Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring class
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:145)
... 12 more



Name and version of the database you are using: PostgreSQL 8.1-beta2



Vielen Dank.


Top
 Profile  
 
 Post subject: funktionierendes Mapping
PostPosted: Mon Nov 14, 2005 6:17 am 
Regular
Regular

Joined: Sat Nov 05, 2005 5:33 am
Posts: 70
Location: Linz, Austria
Poste bitte doch auch mal das funktionierende Mapping.
Dann kann man die Unterschiede leicht raussuchen.

Heinz


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 14, 2005 11:24 am 
Newbie

Joined: Sun Nov 13, 2005 2:52 pm
Posts: 2
Ohne

Quote:
<joined-subclass name="de.hrportal.urlaubsverwaltung.db.UrlaubData" lazy="true" table="urlaub" entity-name="urlaub">
<key column="user_id"/>
<property name="von" type="date" column="von" not-null="true"/>
<property name="bis" type="date" column="bis" not-null="true"/>
<property name="status" type="string" not-null="false"/>
</joined-subclass>


gehts.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 15, 2005 2:47 am 
Regular
Regular

Joined: Sat Nov 05, 2005 5:33 am
Posts: 70
Location: Linz, Austria
Post bitte noch die UrlaubData-Klasse.
Ich glaube in dieser ist das Problem.

Hast Du dort auch get/setUserId?

Heinz


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.