Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Hibernate property references  RSS feed

Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In a hibernate mapping, is it possible to define a reference to property using dot notations such as:


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


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

R. Alcazar
Posts: 17314
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • 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?

Ricardo Alcazar
Posts: 11
  • Mark post as helpful
  • send pies
  • 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:

- 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?

R. Alcazar
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • 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.
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!