• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Hibernate property references

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In a hibernate mapping, is it possible to define a reference to property using dot notations such as:

<code>

<hibernate-mapping>
<property name="myProperty.anotherProperty" type="string" not-null="true" column="dbproperty" />
</hibernate-mapping>

</code>

I'm trying to solve an issue with my mappings concerning this. Any help is appreciated.

Thanks!
R. Alcazar
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds like a relationship to me. I would probably have two different mappings with either a one to one or one to many.

What is the purpose of needing this?

Mark
 
Ricardo Alcazar
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mark -

This is my first attempt at managing a foreign-key relationship with hibernate so please bear with me.

Instances of my User class are maintained in an LDAP directory, task instances are stored in my relational DB. A quick look at my class definitions are as follows (instance values displayed in parens):

class User
- String dn (cn=john doe,o=myorganization)
- String firstName (john)
- String lastName (doe)

class Task
- int id (43)
- String name (mytask)
- User owner (*objectref*)

I would like to store the "dn" of the user instance in a task record. The resulting DB record is below:

mydb.dbo.tasks
- id (43)
- name (mytask)
- owner (cn=john doe,o=myorganization)

I have considered two approaches to resolving this issue, but they are based on my limited experience with hibernate. Perhaps you can make a recommendation:

1.) Store User instances in a DB table and define a one-to-one relationship.

2.) Store only the "dn" in the Task record and use a DAO to create the user instance from an LDAP directory.

My second approach seems best, however, I'm not sure of the appropriate way to handle the mapping. I assumed a dot-notation in the mappings file to write the "dn" to the task record (please see my initial post). Can you provide a recommendation?

Thanks!
R. Alcazar
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your second approach does sound better; there is no point storing User data in both LDAP and a table in your database. And since Task and User are related, it would make sense to define this relationship as an association in your mapping file. However, Hibernate's only purpose is to map Objects to Relational data, and since LDAP is not relational you can't use Hibernate to map data stored in there. You can happily have your User association defined in your Task class, but not in the mapping file. So I'd do that, and leave it up to the DAO to handle that this particular association comes from LDAP, not Hibernate.
 
reply
    Bookmark Topic Watch Topic
  • New Topic