Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 13 posts ] 
Author Message
 Post subject: Hibernate complains about missing property?
PostPosted: Fri Mar 14, 2008 11:54 am 
Beginner
Beginner

Joined: Thu Jan 31, 2008 7:09 am
Posts: 34
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate</artifactId>
<version>3.2.5.ga</version>
</dependency>

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.3.0.ga</version>
</dependency>

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>3.3.1.ga</version>
</dependency>

Mapping documents:
JPA
Code between sessionFactory.openSession() and session.close():
Spring handled
Full stack trace of any exception that occurs:

Name and version of the database you are using:
Mysql 5.05
The generated SQL (show_sql=true):
NA
Debug level Hibernate log excerpt:
NA

I have the following structure:

@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public abstract class Mammal

private Person owner;


@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public class Cat extends Mammal;



And heres the interesting part:

@Entity
@Table(name = "PERSON")
public class Person

@Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
@OneToMany(cascade = { CascadeType.PERSIST, CascadeType.MERGE,
CascadeType.REMOVE }, mappedBy="owner")
private List<Cat> cats = new ArrayList<Cat>();

I get this error:

javax.persistence.PersistenceException: org.hibernate.AnnotationException: mappedBy reference an unknown target entity property:
Cat.owner in Person.cats

Now I sorta can see what the error is about, but since cat extends mammal it does actually have and owner.

What am I doing wrong?


Top
 Profile  
 
 Post subject: Re: Hibernate complains about missing property?
PostPosted: Fri Mar 14, 2008 12:05 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 734
Location: Montreal, QC
Look at the persistence.xml file and see if you are excluding unlisted clsasses. I think this error is complaining it does not know Cat as an entity.



Farzad-


Top
 Profile  
 
 Post subject: Re: Hibernate complains about missing property?
PostPosted: Fri Mar 14, 2008 1:50 pm 
Beginner
Beginner

Joined: Thu Jan 31, 2008 7:09 am
Posts: 34
farzad wrote:
Look at the persistence.xml file and see if you are excluding unlisted clsasses. I think this error is complaining it does not know Cat as an entity.



Farzad-


Im not excluding anything, but Im not including the Mammal class, i'll do that and see what happens..


[EDIT]
No that did not help either.. So im still puzzeld by this.


Top
 Profile  
 
 Post subject: Re: Hibernate complains about missing property?
PostPosted: Thu Mar 20, 2008 10:05 am 
Beginner
Beginner

Joined: Thu Jan 31, 2008 7:09 am
Posts: 34
ninomartinez wrote:
farzad wrote:
Look at the persistence.xml file and see if you are excluding unlisted clsasses. I think this error is complaining it does not know Cat as an entity.



Farzad-


Im not excluding anything, but Im not including the Mammal class, i'll do that and see what happens..


[EDIT]
No that did not help either.. So im still puzzeld by this.


So nobody has an idea what causes this? Should I try to explain another way?


regards Nino


Top
 Profile  
 
 Post subject: Re: Hibernate complains about missing property?
PostPosted: Thu Mar 20, 2008 2:05 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 734
Location: Montreal, QC
Can you send me the persistence.xml file? I am not sure but may be we can see something in it that shows the problem.



Farzad-


Top
 Profile  
 
 Post subject: Re: Hibernate complains about missing property?
PostPosted: Sat Mar 22, 2008 11:32 am 
Beginner
Beginner

Joined: Thu Jan 31, 2008 7:09 am
Posts: 34
farzad wrote:
Can you send me the persistence.xml file? I am not sure but may be we can see something in it that shows the problem.



Farzad-



<?xml version="1.0" encoding="UTF-8"?>

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/ ... ce_1_0.xsd"
version="1.0">

<!-- persistence.xml -->

<persistence-unit name="zeuzPersistance">
<!-- The provider only needs to be set if you use several JPA providers -->
<provider>org.hibernate.ejb.HibernatePersistence</provider>

<class>zeuzgroup.core.BodyPart</class>
<class>zeuzgroup.core.exercise.ExerciseCategory</class>
<class>zeuzgroup.core.exercise.Exercise</class>
<class>zeuzgroup.core.Person</class>
<class>zeuzgroup.core.user.ValidationCode</class>

<class>zeuzgroup.core.Weight</class>
<class>zeuzgroup.core.trainingscheme.TrainingSchemeAbstract</class>
<class>zeuzgroup.core.trainingscheme.TrainingScheme</class>
<class>
zeuzgroup.core.trainingscheme.TrainingSchemeTemplate
</class>

<properties>
<!-- Scan for annotated classes -->
<property name="hibernate.archive.autodetection"
value="class" />


<!-- SQL stdout logging -->
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="false" />
<property name="use_sql_comments" value="false" />


<!-- Connecting to mySQL -->
<property name="hibernate.dialect"
value="org.hibernate.dialect.MySQLDialect" />
<property name="hibernate.connection.driver_class"
value="com.mysql.jdbc.Driver" />
<property name="hibernate.connection.url"
value="jdbc:mysql://localhost:3306/ZeuzTest" />
<property name="hibernate.connection.username" value="root" />




<property name="hibernate.hbm2ddl.auto" value="create-drop" />







<property name="hibernate.c3p0.acquire_increment" value="1" />
<property name="hibernate.c3p0.idle_test_period"
value="14400" />
<property name="hibernate.c3p0.timeout" value="25200" />
<property name="hibernate.c3p0.max_size" value="8" />
<property name="hibernate.c3p0.min_size" value="3" />
<property name="hibernate.c3p0.max_statements" value="0" />


</properties>
</persistence-unit>

</persistence>





where as

<class>zeuzgroup.core.trainingscheme.TrainingSchemeAbstract</class>
<class>zeuzgroup.core.trainingscheme.TrainingScheme</class>

TrainingScemeAbstract are mammal and trainingScheme are cat...


Top
 Profile  
 
 Post subject: Re: Hibernate complains about missing property?
PostPosted: Mon Mar 24, 2008 8:36 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 734
Location: Montreal, QC
Well the first problem in your files is that Person.trainingSchemes (cats) is referencing owner which is a one-to-one. That's not going to work. It has to be a many-to-one. Fix this and tell me if you still have the problem.



Farzad-


Top
 Profile  
 
 Post subject: Re: Hibernate complains about missing property?
PostPosted: Tue Mar 25, 2008 2:48 am 
Beginner
Beginner

Joined: Thu Jan 31, 2008 7:09 am
Posts: 34
farzad wrote:
Well the first problem in your files is that Person.trainingSchemes (cats) is referencing owner which is a one-to-one. That's not going to work. It has to be a many-to-one. Fix this and tell me if you still have the problem.



Farzad-


Great point! I fixed it, but it still does not work..

Stil giving the error:

javax.persistence.PersistenceException: org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: zeuzgroup.core.trainingscheme.TrainingScheme.owner in zeuzgroup.core.Person.trainingSchemes


I saw somewhere that polymorphism support were partially lacking in hibernate, or were some what an experimental feature, however this thread where from 2005.. And I am hoping that it has improved..?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 25, 2008 10:06 am 
Beginner
Beginner

Joined: Thu Jan 31, 2008 7:09 am
Posts: 34
Hmmm it seems I've successfully replicated the problem.:/

It comes when you use the mappedby with an property from a parent class in a child class.


For example if you have mammal and cat which is a child of mammal.

If you reference a list of mammals from person no problems. If you do the same with cat you get the exception.

You can see the sample code here which gives the error(run mvn test to see the failure):

http://www.savefiles.net/d/ify24gzhj3pb.html


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 26, 2008 3:12 pm 
Beginner
Beginner

Joined: Thu Jan 31, 2008 7:09 am
Posts: 34
I've just finished testing the above source against openJPA and it does not fail with their implementation. In my opinion it seems like a bug in Hibernate polymorphism support, or lack there of.

How should I report the error, is there a jira or something?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 26, 2008 4:00 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 734
Location: Montreal, QC
ninomartinez wrote:
How should I report the error, is there a jira or something?



There you go: http://hibernate.org/217.html


Sorry I didn't get the time to look at the code.


Farzad-


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 27, 2008 4:08 am 
Beginner
Beginner

Joined: Thu Jan 31, 2008 7:09 am
Posts: 34
Farzad, thanks for your help



Okay jira entered:

http://opensource.atlassian.com/project ... se/ANN-720


Top
 Profile  
 
 Post subject: Re: Hibernate complains about missing property?
PostPosted: Mon Nov 28, 2011 6:59 am 
Newbie

Joined: Mon Nov 28, 2011 6:51 am
Posts: 1
I would like those interested in support for this feature, the ability to map to a (effectively redefined) property inherited into a subclass (which is handled ok by EclipseLink and OpenJPA) I invite you to inspect my remarks at:

Hibernate Core HHH-4233 cant bind a child using mappedby relating to a parent attribute(polymorphism)

With particular reference to the UML diagram attachment at:

https://hibernate.onjira.com/secure/att ... rphism.png


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 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.