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.  [ 9 posts ] 
Author Message
 Post subject: Trouble making one-to-one associations
PostPosted: Thu Oct 23, 2003 10:52 am 
Newbie

Joined: Thu Oct 23, 2003 9:50 am
Posts: 4
Hello,
I'm having trouble deploying objects containing one-to-one associations. I've used one-to-many(collection) types of assocation with no fuss, this is a first time i'm playing with one-to-one ones.

Having the following xdoclet in my object works just fine. Not he use of class = "fi.jab.poc.Role" which causes no problem.

Code:
/**
    * @hibernate.set order-by = "role_id" cascade = "all"
    * @hibernate.collection-key column = "user_id" 
    * @hibernate.collection-one-to-many class = "fi.jab.poc.Role"
    */
   public Collection getRoles() {
      return roles;
   }


But when i'm trying to use the same class (which is also Hibernated object) with one-to-one i've to make it implement Serializable otherwise there'll be some deployment time exceptions thrown from Binder.getTypeFromXML-method.

Here's the xdoclet configuration for the offending part:
Code:
   /**
    * @return
    * @hibernate.property
    * @hibernate.one-to-one
    */
   public Person getPerson() {
      return person;
   }



Code:
17:11:10,011 INFO  [Binder] Mapping class: fi.jab.poc.LogItem -> JAB_LOGITEM
17:11:42,668 ERROR [Configuration] Could not compile the mapping document
net.sf.hibernate.MappingException: Could not interpret type: fi.jab.poc.Person
   at net.sf.hibernate.cfg.Binder.getTypeFromXML(Binder.java:788)
   at net.sf.hibernate.cfg.Binder.bindValue(Binder.java:354)
   at net.sf.hibernate.cfg.Binder.propertiesFromXML(Binder.java:891)
   at net.sf.hibernate.cfg.Binder.bindRootClass(Binder.java:294)
   at net.sf.hibernate.cfg.Binder.bindRoot(Binder.java:1095)
   at net.sf.hibernate.cfg.Configuration.add(Configuration.java:230)
   at net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java:252)
   at net.sf.hibernate.cfg.Configuration.addResource(Configuration.java:273)
   at net.sf.hibernate.jmx.HibernateService.buildSessionFactory(HibernateService.java:160)
   at net.sf.hibernate.jmx.HibernateService.start(HibernateService.java:131)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:324)
   at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatcher.java:284)
   at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:546)
   at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:976)
   at $Proxy14.start(Unknown Source)


Maybe i'm just missing something, can someone point me to proper documentation/examples?
Or is it neccaccery for one-to-one referenced object to be either serializable or one of the other types mentioned in TypeFactory.hueristicType (maybe a typo?)?


Top
 Profile  
 
 Post subject: Re: Trouble making one-to-one associations
PostPosted: Thu Oct 23, 2003 12:20 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Quote:
Maybe i'm just missing something, can someone point me to proper documentation/examples?
Or is it neccaccery for one-to-one referenced object to be either serializable or one of the other types mentioned in TypeFactory.hueristicType (maybe a typo?)?


Person must be serializable and mapped.[/quote]

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 23, 2003 1:43 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Why should it be serializable?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 23, 2003 4:17 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
gavin wrote:
Why should it be serializable?

Because I'm wrong ;-)
I mismatch component class used as a composite identifier requirements with mapped class requirements.


jarkko, Person class implements Type interface ? Is there a reason ?
Havea closer look at Javadoc of Type AND UserType. Have a look at section 4.2.4 of the reference guide.

Your mapping fails because Hibernate cannot instanciate Person (Person.newInstance()). Does Person have a default (no args) constructor ?[/quote]

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 23, 2003 4:22 pm 
Newbie

Joined: Thu Oct 23, 2003 9:50 am
Posts: 4
gavin wrote:
Why should it be serializable?


Actually the real question i'm trying to ask is that why it's working when Person is placed inside a Collection (in the many-to-one-case) and why it should be modified when used "directly" in the one-to-one-case?

Any reason for this one or am i still mislooking something?


Top
 Profile  
 
 Post subject: Re: Trouble making one-to-one associations
PostPosted: Thu Oct 23, 2003 5:32 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Code:
   /**
    * @return
    * @hibernate.property
    * @hibernate.one-to-one
    */
   public Person getPerson() {
      return person;
   }

Forget what I said, it was totally wrong. The broken part is due to the @hibernate.property tag, not the one-to-one.

Property has to be an Hibernate type (basic, UserType, ...)
A serializable class can be mapped on the Hibernate SerializableType.

I don't understand why you need to map person as a Property AND a one-to-one.

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Re: Trouble making one-to-one associations
PostPosted: Fri Oct 24, 2003 12:53 am 
Newbie

Joined: Thu Oct 23, 2003 9:50 am
Posts: 4
I made some changes to the xdoclet to make it more obvious what i was trying to reach:
Code:
/**
    * @hibernate.property  column = "person_id"
    * @hibernate.one-to-one  class = "fi.jab.poc.Person"
    */
   public Person getPerson() {
      return person;
   }


And here's the Hibernate mapping generated from it:
Code:
        <property
            name="person"
            type="fi.jab.poc.Person"
            update="true"
            insert="true"
            column="person_id"
        />

        <one-to-one
            name="person"
            class="fi.jab.poc.Person"
            cascade="none"
            outer-join="auto"
            constrained="false"
        />


So it seems (haven't tested it) that to archieve what i want i need the following xdoclet:
Code:
   /**
    * @hibernate.property  column = "person_id" type = "fi.jab.poc.Person"
    */

Which translates to
Code:
    <property
            name="person"
            type="fi.jab.poc.Person"
            update="true"
            insert="true"
            column="person_id"
        />



Maybe i was a little confused with the term "one-to-one", but thanks for the info i'll look it from the document.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 24, 2003 12:55 am 
Newbie

Joined: Thu Oct 23, 2003 9:50 am
Posts: 4
Ah, no. If the type in property has to be HibernateType the above won't still work.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 24, 2003 2:39 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
If I understand you well, what you need is

Code:
<one-to-one
            name="person"
            class="fi.jab.poc.Person"
            property-ref="person-id"
        />


This is a 2.1 beta1 and + feature.
I don't know if it is doable with xdoclet.

On 2.0.x, Person PK must match The other class PK (behavior wo property-ref).

Your mapping isn't good, You shoud not map a property and a one-to-one to the same attribute. One to one already map the attribute. Actually, I do not know how your mapping works.

Have a look at http://forum.hibernate.org/viewtopic.php?t=924804&highlight=propertyref

Remove
Code:
@hibernate.property  column = "person_id"

And update your mapping with the property-ref attribute.

_________________
Emmanuel


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