-->
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.  [ 8 posts ] 
Author Message
 Post subject: MappingException: No persister for:
PostPosted: Mon Dec 08, 2003 3:42 pm 
Newbie

Joined: Mon Dec 08, 2003 2:48 pm
Posts: 2
Location: Vienna, Austria
Hi,

I have one abstract class:

abstract public class Party {
}

and two subclasses which extend it:

public class Supplier extends Party {
...
}

public class Customer extends Party {
...
}

and table-per-class-hierarchy mapping:

<hibernate-mapping>
<class
name="xxx.Party"
table="parties"
dynamic-update="false"
dynamic-insert="false"
discriminator-value="null"
>

<id
name="id"
column="part_id"
type="java.lang.Long"
>
<generator class="native">
</generator>
</id>

<discriminator
column="part_type"
type="java.lang.String"
length="1"
/>

... some properties hier .....

<subclass
name="xxx.Supplier"
dynamic-update="false"
dynamic-insert="false"
discriminator-value="S"
>

</subclass>


<subclass
name="xxx.Customer"
dynamic-update="false"
dynamic-insert="false"
discriminator-value="C"
>
</class>

....
</hibernate-mapping>

when trying to persist the subclass with:

ses.SaveorUpdate( SupplierObject)

I got Exception:

[list]net.sf.hibernate.MappingException: No persister for: xxx.Supplier
at net.sf.hibernate.impl.SessionFactoryImpl.getPersister(SessionFactoryImpl.java:420)
at net.sf.hibernate.impl.SessionImpl.getPersister(SessionImpl.java:2302)
at net.sf.hibernate.impl.SessionImpl.getPersister(SessionImpl.java:2309)
at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1195)[/list]

Have I missed something, or is this way of persisting subclass not supported by Hibenate. If not, how to workaround it ? I'm using 2.1rc1.

regards

Jack


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 09, 2003 7:41 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Hum should work to me, except that discriminator-value="null" cannot be inserted into your discriminator column (length=1).

Any log during the hibernate initialization phase to focus on the pb ?
Are you sure you're using this mapping in your hibernate.cfg.xml

_________________
Emmanuel


Top
 Profile  
 
 Post subject: no persiter for: subclass
PostPosted: Thu Jan 08, 2004 5:35 pm 
Newbie

Joined: Thu Jan 08, 2004 4:51 pm
Posts: 13
Hello

I think I'm facing the same problem. I summarized my problem in the following very basic application. It looks like a very standard situation to me.

I got 2 model classes: Person and Doctor. Doctor inherits from person. I tried to save an Doctor in a Console application.

this are the 2 model classes:

The Person Class:


/**
*@hibernate.class
* discriminator-value="person"
*@hibernate.discriminator
* column="discrimator"
* type="string"
*/
public class Person
{
Long id;

String firstName;
String lastName;

public Person(){}

public Person(String firstName,String lastName)
{
this.firstName = firstName;
this.lastName = lastName;
}

/**
* @hibernate.id
* generator-class="native"
*/
public Long getId()
{
return id;
}
public void setId(Long id)
{
this.id=id;
}

/**
*@hibernate.property
*/
public String getFirstName()
{
return firstName;
}
public void setFirstName(String firstName)
{
this.firstName=firstName;
}

/**
*@hibernate.property
*/
public String getLastName()
{
return lastName;
}
public void setLastName(String lastName)
{
this.lastName=lastName;
}
}



The Doctor Class:


/**
*@hibernate.subclass
* discriminator-value="doctor"
*/
public class Doctor extends Person
{
String specialisation;

public Doctor(){}

public Doctor(String firstName,String lastName,String specialisation)
{
super(firstName,lastName);
this.specialisation=specialisation;
}
/**
*@hibernate.property
*/
public String getSpecialisation()
{
return specialisation;
}
public void setSpecialisation(String specialisation)
{
this.specialisation=specialisation;
}
}



This is the mapping generated by Xdoclet:

<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
<class
name="generalClasses.Person"
dynamic-update="false"
dynamic-insert="false"
discriminator-value="person"
>

<id
name="id"
column="id"
type="java.lang.Long"
>
<generator class="native">
</generator>
</id>

<discriminator
column="discrimator"
type="string"
/>

<property
name="firstName"
type="java.lang.String"
update="true"
insert="true"
column="firstName"
/>

<property
name="lastName"
type="java.lang.String"
update="true"
insert="true"
column="lastName"
/>

<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-Person.xml
containing the additional properties and place it in your merge dir.
-->
<subclass
name="generalClasses.Doctor"
dynamic-update="false"
dynamic-insert="false"
discriminator-value="doctor"
>
<property
name="specialisation"
type="java.lang.String"
update="true"
insert="true"
column="specialisation"
/>

<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-Doctor.xml
containing the additional properties and place it in your merge dir.
-->

</subclass>

</class>

</hibernate-mapping>



Finally I tried to save the Doctor subclass with the following console application:


class TestHib
{
public static void main(String args[]) throws Exception
{

Doctor doc = new Doctor("doctor","Evil","Evil things");

SessionFactory sesFac = new Configuration().configure().buildSessionFactory();
Session hibSession= sesFac.openSession();
Transaction transaction =hibSession.beginTransaction();

hibSession.save(doc);

transaction.commit();
hibSession.close();


}
}


This unfortunately resulted in the following errors:

Exception in thread "main" net.sf.hibernate.MappingException: No persister for: Doctor
at net.sf.hibernate.impl.SessionFactoryImpl.getPersister(SessionFactoryImpl.java:344)
at net.sf.hibernate.impl.SessionImpl.getClassPersister(SessionImpl.java:2574)
at net.sf.hibernate.impl.SessionImpl.getPersister(SessionImpl.java:2581)
at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:725)
at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:717)
at TestHib.main(TestHib.java:24)


This looks like a very standard problem to me. I must be overlooking something here. Could anybody please help me out.

Thank you


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 08, 2004 5:47 pm 
Regular
Regular

Joined: Wed Jan 07, 2004 5:16 pm
Posts: 65
Location: CA, USA
Is your Doctor class in the package you have named in the mapping file?

eg generalClasses.Doctor ?

I saw an error like this when I was trying to save a class that I had not correctly defined (eg package and class name) in the mapping file.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 09, 2004 5:37 am 
Newbie

Joined: Thu Jan 08, 2004 4:51 pm
Posts: 13
yes, both Doctor and Person are in the package generalClasses.

Doctor and Person have 'package generalClasses;' as the first line of code. The console application imports that package. So I don't think that could be the problem.

I should have copied the 'package-lines' in my post, sorry for that.

One more thing that might be important to solve this problem: I do can save a Person whithout problems. Only saving a Doctor poses a problem.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 09, 2004 5:55 am 
Newbie

Joined: Mon Dec 08, 2003 2:48 pm
Posts: 2
Location: Vienna, Austria
ok, solved this problem and the reason in my case was not loaded mapping file. I discovereed this after enabling log4j in debug mode.
I have my hibernane.cfg.xml in root of classpath and mapping files in package, so I reference mappings from config file like this:
<mapping resource="com/xxx/yyy/DomainObject.hbm.xml"/>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 09, 2004 10:43 am 
Newbie

Joined: Thu Jan 08, 2004 4:51 pm
Posts: 13
I don't think that's the problem in my case since the mapping of Doctor is included in the mapping of Person. And the mapping of Person is certainly loaded because I'm able to save a Person.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 10, 2004 12:33 pm 
Newbie

Joined: Thu Jan 08, 2004 4:51 pm
Posts: 13
OK, I found the problem. And of course it was a stupid mistake.

I had 2 Doctor.class files. One in the normal package directory structure and one directly in the root which I didn't notice. Apparently hibernate or java itself always used this .class file. I deleted it and the problem was solved.

Anyway, thanks for the suggestions

greetz

Peter


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