-->
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.  [ 5 posts ] 
Author Message
 Post subject: MappingException - No Persister
PostPosted: Wed Feb 04, 2004 12:53 pm 
Newbie

Joined: Wed Feb 04, 2004 12:33 pm
Posts: 13
Location: Vienna/Austria
Dear Hibernate Staff,

I'm a first time player with hibernate, read the reference manually and the posting guidelines, but I'm running into troubles when saving an Object with many-to-one and one-to-one mappings ...

MasterObject is Citizen, which references via foreign key one record in a Salutation Lookup Table (many-to-one)

Citizen references also via foreign key one record in the Country Lookup Table (many-to-one)

Citizen references via foreign key exactly one correlating record in 1:1 related table Adress.

with the following code

== CODE ============================
PropertyConfigurator.configure("src/test/log4j.properties.test");

Configuration cfg = new Configuration()
.addClass(at.mobilkom.a1signatur.business.hibernate.Citizen.class)
.addClass(at.mobilkom.a1signatur.business.hibernate.Address.class)
.addClass(at.mobilkom.a1signatur.business.hibernate.Country.class)
.addClass(at.mobilkom.a1signatur.business.hibernate.Salutation.class);
log.info("after creating configuration");

SessionFactory sessionFactory = new Configuration().buildSessionFactory();
log.info("after building sessionFactory");

ResourceLocator loc = ResourceLocator.getInstance();
DataSource ds = (DataSource) loc.getCachableResource("jdbc/TestDataSource");
log.info("after retrieving dataSource");

Connection conn = ds.getConnection();
log.info("after establishing connection");

Salutation salutation = new Salutation(3, "Captain");
log.info(salutation);

Country nationality = new Country("WL", "Wonderland", null);
log.info(nationality);

Address address = new Address();
address.setAddressId(1);
address.setStreet("Rg");
address.setNo("32/10-11");
address.setPostCode("1050");
address.setCity("Wien");
address.setCountry(nationality);
log.info(address);

Citizen citizen = new Citizen();
citizen.setSalutation(salutation);
citizen.setNationality(nationality);
citizen.setBirthdate_day((short) 2);
citizen.setBirthdate_month((short) 9);
citizen.setBirthdate_year((short) 1975);
citizen.setAddress(address);
citizen.setFirstName("Klaus");
citizen.setLastName("Unger");
citizen.setCompanyName("IT-Consulting");
citizen.setTitle("n/a");

log.info(citizen);

Session session = sessionFactory.openSession(conn);
Transaction tx = null;

log.info("after opening session");

try {
tx = session.beginTransaction();

log.info("before save citizen");
session.save(citizen);
log.info("after save citizen");

tx.commit();
}
catch (HibernateException he) {
if (tx != null) tx.rollback();
log.error("Hibernate Exception occured: ", he);
}
finally {
session.close();
}
== END CODE =========================

I receive the following console output

== CONSOLE ==========================
04 Feb 2004 17:31:31.197 INFO : Hibernate 2.1.1
04 Feb 2004 17:31:31.207 INFO : loaded properties from resource hibernate.properties: {hibernate.cache.provider_class=net.sf.hibernate.cache.HashtableCacheProvider, hibernate.cglib.use_reflection_optimizer=false, hibernate.connection.pool_size=0, hibernate.dialect=net.sf.hibernate.dialect.OracleDialect, hibernate.show_sql=false, hibernate.connection.datasource=java:comp/env/jdbc/A1BKDataSourceRef}
04 Feb 2004 17:31:31.217 INFO : Mapping resource: at/mobilkom/a1signatur/business/hibernate/Citizen.hbm.xml
04 Feb 2004 17:31:31.387 DEBUG: trying to locate http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath under net/sf/hibernate/
04 Feb 2004 17:31:31.397 DEBUG: found http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath
04 Feb 2004 17:31:31.578 INFO : Mapping class: at.mobilkom.a1signatur.business.hibernate.Citizen -> Citizens
04 Feb 2004 17:31:31.658 DEBUG: Mapped property: citizenId -> CitizenId, type: long
04 Feb 2004 17:31:31.688 DEBUG: Mapped property: address, type: at.mobilkom.a1signatur.business.hibernate.Address
04 Feb 2004 17:31:31.688 DEBUG: Mapped property: birthdate_day -> Birthdate_day, type: short
04 Feb 2004 17:31:31.698 DEBUG: Mapped property: birthdate_month -> Birthdate_month, type: short
04 Feb 2004 17:31:31.698 DEBUG: Mapped property: birthdate_year -> Birthdate_year, type: short
04 Feb 2004 17:31:31.698 DEBUG: Mapped property: companyName -> CompanyName, type: string
04 Feb 2004 17:31:31.698 DEBUG: Mapped property: firstName -> FirstName, type: string
04 Feb 2004 17:31:31.698 DEBUG: Mapped property: lastName -> LastName, type: string
04 Feb 2004 17:31:31.698 DEBUG: Mapped property: nationality, type: at.mobilkom.a1signatur.business.hibernate.Country
04 Feb 2004 17:31:31.708 DEBUG: Mapped property: salutation, type: at.mobilkom.a1signatur.business.hibernate.Salutation
04 Feb 2004 17:31:31.708 DEBUG: Mapped property: title -> Title, type: string
04 Feb 2004 17:31:31.708 INFO : Mapping resource: at/mobilkom/a1signatur/business/hibernate/Address.hbm.xml
04 Feb 2004 17:31:31.708 DEBUG: trying to locate http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath under net/sf/hibernate/
04 Feb 2004 17:31:31.708 DEBUG: found http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath
04 Feb 2004 17:31:31.748 INFO : Mapping class: at.mobilkom.a1signatur.business.hibernate.Address -> Addresses
04 Feb 2004 17:31:31.758 DEBUG: Mapped property: addressId -> AddressId, type: long
04 Feb 2004 17:31:31.758 DEBUG: Mapped property: buildingName -> BuildingName, type: string
04 Feb 2004 17:31:31.758 DEBUG: Mapped property: city -> City, type: string
04 Feb 2004 17:31:31.758 DEBUG: Mapped property: country -> Country, type: at.mobilkom.a1signatur.business.hibernate.Country
04 Feb 2004 17:31:31.758 DEBUG: Mapped property: no -> No, type: string
04 Feb 2004 17:31:31.758 DEBUG: Mapped property: postCode -> PostCode, type: string
04 Feb 2004 17:31:31.758 DEBUG: Mapped property: street -> Street, type: string
04 Feb 2004 17:31:31.758 INFO : Mapping resource: at/mobilkom/a1signatur/business/hibernate/Country.hbm.xml
04 Feb 2004 17:31:31.768 DEBUG: trying to locate http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath under net/sf/hibernate/
04 Feb 2004 17:31:31.768 DEBUG: found http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath
04 Feb 2004 17:31:31.808 INFO : Mapping class: at.mobilkom.a1signatur.business.hibernate.Country -> L_Countries
04 Feb 2004 17:31:31.808 DEBUG: Mapped property: countryCode -> CountryCode, type: string
04 Feb 2004 17:31:31.808 DEBUG: Mapped property: description -> Description, type: string
04 Feb 2004 17:31:31.808 DEBUG: Mapped property: name -> Name, type: string
04 Feb 2004 17:31:31.808 INFO : Mapping resource: at/mobilkom/a1signatur/business/hibernate/Salutation.hbm.xml
04 Feb 2004 17:31:31.808 DEBUG: trying to locate http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath under net/sf/hibernate/
04 Feb 2004 17:31:31.808 DEBUG: found http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath
04 Feb 2004 17:31:31.848 INFO : Mapping class: at.mobilkom.a1signatur.business.hibernate.Salutation -> L_Salutations
04 Feb 2004 17:31:31.848 DEBUG: Mapped property: salutationId -> SalutationId, type: long
04 Feb 2004 17:31:31.848 DEBUG: Mapped property: value -> Value, type: string
04 Feb 2004 17:31:31.848 INFO : after creating configuration
04 Feb 2004 17:31:31.848 INFO : processing one-to-many association mappings
04 Feb 2004 17:31:31.848 INFO : processing one-to-one association property references
04 Feb 2004 17:31:31.848 INFO : processing foreign key constraints
04 Feb 2004 17:31:31.878 INFO : Using dialect: net.sf.hibernate.dialect.OracleDialect
04 Feb 2004 17:31:31.888 INFO : Use outer join fetching: true
04 Feb 2004 17:31:31.888 INFO : JNDI InitialContext properties:{}
04 Feb 2004 17:31:33.611 INFO : Using datasource: jdbc/TestDataSource
04 Feb 2004 17:31:33.621 INFO : No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)
04 Feb 2004 17:31:34.352 INFO : Use scrollable result sets: true
04 Feb 2004 17:31:34.352 INFO : JDBC 2 max batch size: 15
04 Feb 2004 17:31:34.352 INFO : echoing all SQL to stdout
04 Feb 2004 17:31:34.352 INFO : Query language substitutions: {}
04 Feb 2004 17:31:34.352 INFO : cache provider: net.sf.hibernate.cache.HashtableCacheProvider
04 Feb 2004 17:31:34.352 INFO : instantiating and configuring caches
04 Feb 2004 17:31:34.562 INFO : building session factory
04 Feb 2004 17:31:34.572 DEBUG: instantiating session factory with properties: {java.vendor=Sun Microsystems Inc., ... hibernate.cache.provider_class=net.sf.hibernate.cache.HashtableCacheProvider, ... hibernate.cglib.use_reflection_optimizer=false, ... hibernate.connection.datasource=jdbc/TestDataSource, ... hibernate.dialect=net.sf.hibernate.dialect.OracleDialect, ...
hibernate.show_sql=true}
04 Feb 2004 17:31:34.762 DEBUG: initializing class SessionFactoryObjectFactory
04 Feb 2004 17:31:34.762 DEBUG: registered: 2c90824afa815ebf00fa815ec1600000 (unnamed)
04 Feb 2004 17:31:34.762 INFO : no JNDI name configured
04 Feb 2004 17:31:34.762 DEBUG: instantiated session factory
04 Feb 2004 17:31:34.762 INFO : after building sessionFactory
04 Feb 2004 17:31:34.832 INFO : after retrieving dataSource
04 Feb 2004 17:31:34.882 INFO : after establishing connection
04 Feb 2004 17:31:34.882 INFO : at.mobilkom.a1signatur.business.hibernate.Salutation - id=3/value=Captain
04 Feb 2004 17:31:34.882 INFO : at.mobilkom.a1signatur.business.hibernate.Citizen - id=0/fName=Klaus/lName=Unger/sal= [at.mobilkom.a1signatur.business.hibernate.Salutation - id=3/value=Captain] /title=n/a/bday=1975/9/2/compName=IT-Consulting/addr= [at.mobilkom.a1signatur.business.hibernate.Address - addressId=1/street=G/buildingName=null/No=32/10-11/postCode=1050/city=Wien/country= [at.mobilkom.a1signatur.business.hibernate.Country - countryCode=WL/name=Wonderland/desc=null] ] /nat= [at.mobilkom.a1signatur.business.hibernate.Country - countryCode=WL/name=Wonderland/desc=null]
04 Feb 2004 17:31:34.943 DEBUG: opened session
04 Feb 2004 17:31:34.943 INFO : after opening session
04 Feb 2004 17:31:34.943 DEBUG: begin
04 Feb 2004 17:31:34.953 DEBUG: current autocommit status:true
04 Feb 2004 17:31:34.953 DEBUG: disabling autocommit
04 Feb 2004 17:31:34.953 INFO : after beginTx
04 Feb 2004 17:31:34.953 INFO : before save citizen
04 Feb 2004 17:31:34.983 DEBUG: rollback
04 Feb 2004 17:31:34.983 DEBUG: transaction completion
04 Feb 2004 17:31:34.993 DEBUG: re-enabling autocommit
04 Feb 2004 17:31:34.993 ERROR: Hibernate Exception occured:
net.sf.hibernate.MappingException: No persister for: at.mobilkom.a1signatur.business.hibernate.Citizen
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)

== END CONSOLE ====================

Any hints, comments, tricks etc. are welcome!
This seems to be a show stopper for me, so it's urgent!

Many thanks in advance

kind regards from snowy Vienna/Austria (no kangaroos :) )
Klaus Unger


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 04, 2004 3:30 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Weird. Can you show the mapping ?

_________________
Emmanuel


Top
 Profile  
 
 Post subject: The Mapping for Citizen
PostPosted: Thu Feb 05, 2004 4:48 am 
Newbie

Joined: Wed Feb 04, 2004 12:33 pm
Posts: 13
Location: Vienna/Austria
Hi,

here goes the mapping for citizen ...

<?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="at.mobilkom.a1signatur.business.hibernate.Citizen"
table="Citizens"
dynamic-update="false"
mutable="false"
>

<id
name="citizenId"
column="CitizenId"
type="long"
unsaved-value="-1"
>
<generator class="sequence">
<param name="sequence">seqCitizenId</param>
</generator>
</id>

<one-to-one
name="address"
class="at.mobilkom.a1signatur.business.hibernate.Address"
cascade="none"
outer-join="auto"
constrained="false"
/>

<property
name="birthdate_day"
type="short"
update="true"
insert="true"
column="Birthdate_day"
not-null="true"
unique="false"
/>

<property
name="birthdate_month"
type="short"
update="true"
insert="true"
column="Birthdate_month"
not-null="true"
unique="false"
/>

<property
name="birthdate_year"
type="short"
update="true"
insert="true"
column="Birthdate_year"
not-null="true"
unique="false"
/>

<property
name="companyName"
type="string"
update="true"
insert="true"
column="CompanyName"
not-null="false"
unique="false"
/>

<property
name="firstName"
type="string"
update="true"
insert="true"
column="FirstName"
not-null="true"
unique="false"
/>

<property
name="lastName"
type="string"
update="true"
insert="true"
column="LastName"
not-null="true"
unique="false"
/>

<one-to-one
name="nationality"
class="at.mobilkom.a1signatur.business.hibernate.Country"
cascade="none"
outer-join="auto"
constrained="false"
/>

<one-to-one
name="salutation"
class="at.mobilkom.a1signatur.business.hibernate.Salutation"
cascade="none"
outer-join="auto"
constrained="false"
/>

<property
name="title"
type="string"
update="true"
insert="true"
column="Title"
not-null="false"
unique="false"
/>

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

</class>

</hibernate-mapping>

any hints urgently needed!
cheers
K.


Top
 Profile  
 
 Post subject: Re: The Mapping for Citizen
PostPosted: Thu Feb 05, 2004 4:52 am 
Newbie

Joined: Wed Feb 04, 2004 12:33 pm
Posts: 13
Location: Vienna/Austria
CaveDiver wrote:
BTW ... I surprisingly found out that the xdoclet attributes UPDATE and INSERT work not correctly for me in many-to-one mappings ...

I stated FALSE, TRUE was generated ...

maybe I'm wrong, just wanted to state some - in my opinion - strange behaviour!

again
thx in advance
K:)

Hi,

here goes the mapping for citizen ...

<?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="at.mobilkom.a1signatur.business.hibernate.Citizen"
table="Citizens"
dynamic-update="false"
mutable="false"
>

<id
name="citizenId"
column="CitizenId"
type="long"
unsaved-value="-1"
>
<generator class="sequence">
<param name="sequence">seqCitizenId</param>
</generator>
</id>

<one-to-one
name="address"
class="at.mobilkom.a1signatur.business.hibernate.Address"
cascade="none"
outer-join="auto"
constrained="false"
/>

<property
name="birthdate_day"
type="short"
update="true"
insert="true"
column="Birthdate_day"
not-null="true"
unique="false"
/>

<property
name="birthdate_month"
type="short"
update="true"
insert="true"
column="Birthdate_month"
not-null="true"
unique="false"
/>

<property
name="birthdate_year"
type="short"
update="true"
insert="true"
column="Birthdate_year"
not-null="true"
unique="false"
/>

<property
name="companyName"
type="string"
update="true"
insert="true"
column="CompanyName"
not-null="false"
unique="false"
/>

<property
name="firstName"
type="string"
update="true"
insert="true"
column="FirstName"
not-null="true"
unique="false"
/>

<property
name="lastName"
type="string"
update="true"
insert="true"
column="LastName"
not-null="true"
unique="false"
/>

<one-to-one
name="nationality"
class="at.mobilkom.a1signatur.business.hibernate.Country"
cascade="none"
outer-join="auto"
constrained="false"
/>

<one-to-one
name="salutation"
class="at.mobilkom.a1signatur.business.hibernate.Salutation"
cascade="none"
outer-join="auto"
constrained="false"
/>

<property
name="title"
type="string"
update="true"
insert="true"
column="Title"
not-null="false"
unique="false"
/>

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

</class>

</hibernate-mapping>

any hints urgently needed!
cheers
K.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 05, 2004 8:41 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Try to save Citizen while commenting any association.
Then add them one by one.

It may be related to a misuse of one-to-one (strange though), but you don't show me the full (simplified) mapping.

BTW, in your design I think you misused 1-to-1, A citizen should be many-to-one with a nationality (others are wrong too I guess).

_________________
Emmanuel


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