This week's book giveaways are in the Scala and Android forums.
We're giving away four copies each of Machine Learning Systems: Designs that scale and Xamarin in Action: Creating native cross-platform mobile apps and have the authors on-line!
See this thread and this one for details.
Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Hibernate property references  RSS feed

 
Greenhorn
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:

<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
Sheriff
Posts: 17314
11
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?

Mark
 
Ricardo Alcazar
Greenhorn
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:

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
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.
 
Not so fast naughty spawn! I want you to know about
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!