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