-->
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.  [ 11 posts ] 
Author Message
 Post subject: Using 'period delimiters' when specifying properties in xml
PostPosted: Sat Dec 17, 2005 12:35 pm 
Regular
Regular

Joined: Sat Jan 22, 2005 6:57 pm
Posts: 50
Location: Chicago
Does Hibernate have a property feature like struts does?

In struts, you can specify 'period delimited' values in your jsp to flatten out the property access of an object. For instance, in your struts form object, you can have a property called Customer that returns a customer object. However, its not the customer you want to display, but the customers name. So, in your jsp, you can access it like this: "customer.name".

Struts will covert the above string into getCustomer().getName().

In hibernate, I find that I am having to write methods for every property that I wish to persist in the database on the object I want to persist. This does not make sense (maybe I am doing it wrong.) Instead, I would like to be able to do the following in my hbm.xml:

<property name="customer.name" column="customername" type="string" not-null="true" />

What would happen is Hibernate would convert the above to getCustomer().getName() and getCustomer().setName(s) accordingly.

Not only will it give me the object accessor flexibility I need, but doing so can help to alleviate writing special org.hibernate.usertype.UserTypes because you could delimit your properties down to basic types.

I have extended the org.hibernate.property.BasicPropertyAccessor to handle this functionality, and it works well. But I was wondering if something already existed?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 17, 2005 12:56 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
<component>

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Interesting.....
PostPosted: Sat Dec 17, 2005 4:20 pm 
Regular
Regular

Joined: Sat Jan 22, 2005 6:57 pm
Posts: 50
Location: Chicago
So let me see. If I have the following classes:

Code:
public class Account {
   private ContactInformation contactInfo;
   
   public ContactInformation getContactInfo() {
        return this.contactInfo;
   }

   public void setContactInformation(ContactInformation info) {
        this.contactInfo = info;
   }
}


public class ContactInformation {
   private EmailAddress emailAddress;
   private Phone phone;

   // getter and setters
}


And I wanted my current Account.hbm.xml to look like this:

Code:
      <set name="contactInfo.phones" inverse="false" lazy="true" cascade="all-delete-orphan">
         <key column="account"/>
         <one-to-many class="data.account.Phone"/>
      </set>


Instead, using the <component> tag, it would appear that I have to use <composite-element> for a collection. So...

Code:
      <set name="contactInfo" inverse="false" lazy="true" cascade="all-delete-orphan">
         <key column="account"/>
          <composite-element class="data.contact.ContactInformation">
              <property name="phones"/>
              <one-to-many class="data.account.Phone"/>
          </composite-element>            
      </set>   


Yes? But there is no support for <one-to-many> with composite-element. Ideas?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 17, 2005 4:26 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
i think you would do best by reading up upon different mapping strategies and what hibernate can do instead of looking it from a more or less non-relevant angle as how struts allows you to *read* data.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Relevancy?
PostPosted: Sun Dec 18, 2005 1:38 am 
Regular
Regular

Joined: Sat Jan 22, 2005 6:57 pm
Posts: 50
Location: Chicago
You may say non-relevant, but for me simplicity and elegance is relevant. It is more than just "reading" data, it is "writing" and "mapping" data as well.

What I have done is easy for a programmer to read, easy to code, and requires no extra special tags or learning. Perhaps the Hibernate team should take a look at what others are doing (like Struts) and not always assume that what is currently done in Hibernate is the best approach.

I am looking for a concrete answer as I have given a concrete problem. I am not looking for "go fish".


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 18, 2005 2:05 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
you are asking for being able to map "a.b.name" without defining how a and b is mapped - "a.b.name" is easy when reading, but how do you construct it ?

That is why you need to define what each element in the path look like.
If you had taken the effort to go look that <component>/<composite-element> actually can include property, many-to-one, list,set, map etc. then you would know that this stuff is already possible to map - but of course not by just specifying "a.b.name" since it describes only how you read a simple value, not how you read and what semantics it has.

And having a set with one-to-many insicde a composite-element shows to me you haven't understood the difference between entities and values.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 18, 2005 9:55 pm 
Regular
Regular

Joined: Sat Jan 22, 2005 6:57 pm
Posts: 50
Location: Chicago
Looks like we are both not understanding. You do not have to know how to map a or b with "a.b.name" because they are not to be mapped. "a.b.name" is a means to an end.

"a.b.name" = "getA().getB().getName()" and "getA().getB().setName(x)" "Name" is the only element mapped to the table. Both A and B are NOT persisted objects in any way. They are only accessors to data.

No need for <composite> or other additives and the hbm.xml stays simplified.

I have it working, and it works great. And works beyond "simple" values Its a shame you do not see the value nor embrase such simplicity as found in other technologies. In fact, that was the reason why I asked the question because to me it was so obvious that it had to be already inside of Hibernate. Guess not.

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 19, 2005 3:58 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
You gotta take it easy with the insults.

How can you create the elements in between when loading data ?
"a" and "b" will be null by default and nothing informs hibernate to create that.

If you are talking about you have made a propertyaccessor that assumes a and b have been created by "something else" then that shows that hibernate already has the means to adapt to users own objectmodels - and you could be a good sport and add it to the wiki.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 19, 2005 11:29 am 
Regular
Regular

Joined: Sat Jan 22, 2005 6:57 pm
Posts: 50
Location: Chicago
No insults intended as I am sure none were intended by you. :)

Actually, its more than a custom property accessor - it includes a required custom org.hibernate.property.Getter and org.hibernate.property.Setter as well.

Hibernate did not already have the means to adapt to my data model, I had to modify the hibernate core code to override Hibernate basic functionality to get it to understand that it is not in control of creation of every element in my model and give it an means to get (and set) data contained in data structures within a persisted object. Both features, it would appear, do not exist in Hibernate today.

Is there an easy way to replace BasicPropertyAccessor via xml with a custom BasicPropertyAccessor? Currently, I just put my BasicPropertyAccessor higher in the classpath.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 19, 2005 1:30 pm 
Newbie

Joined: Thu Dec 15, 2005 8:31 am
Posts: 10
Take a look at OGNL from OpenSymphony.com. It might be more then you are looking for...


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 19, 2005 6:10 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
access="yourCustomAccessor"

_________________
Max
Don't forget to rate


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