-->
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: Mapping Java classes to Business labels
PostPosted: Mon Jul 04, 2005 5:37 pm 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
If anyone out there has figured out a clever way to do this, let me know. Basically, I want to perform mappings such as

"com.domain.Customer" = "Client"
"net.domain.Item" = "Item"
"org.domain.CustomerItem" = "Purchase"

This way, when the business side of the project want to replace "Purchase" with "Procurement", I make a change in one configuration file, instead of 10 changes in a bunch of presentation tier components.

In a perfect world, I could write:

<hibernate-mapping>
<class name="org.domain.CustomerItem" label="Procurement" table="customer_item">
...
</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 04, 2005 5:42 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Huh?


Are you looking for entity-name?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 04, 2005 5:56 pm 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
Hibernate basically maps a set of database concepts to java concepts. That's great, I've always had a need for this on a lot of programming platforms. But on every project I have always wanted to map those java concepts to business concepts. Lets say I have the following:

tablename = "cust" -> classname = "Customer"
column1 = "cust_f_name" -> property = "firstName"

Now, I want to be able to do this:

tablename = "cust" -> classname = "Customer" -> Business Label = "Client"
column1 = "cust_f_name" -> property = "firstName" -> Business Label = "First Name"

This is because for me, the business labels change more often during the development phase than the other two "layers". The other week the business unit wanted "Features" changed to "Attractions". I had to hunt through a dozen JSPs and manually change all the instances where I had hard coded "Features". Hibernate has provided me a lot flexibility mapping classes to table names. When the database designer changes the name of a table, I just change a value in a config file. But when I am forced to make a change in the "next layer" it takes forever.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 04, 2005 6:07 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
So, you want a String label for each entity and property. Thats rather trivial, right?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 04, 2005 6:16 pm 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
You could make it more complex if you wanted. For example,

<hibernate-mapping>
<class name="org.domain.CustomerItem" table="customer_item">
<labels>
<label locale="en-US" value="Procurement" />
<label locale="de-GE" value="Beschaffung" />
<label locale="clingon" value="askjdfkja#()&&sdfh" />
<label locale="en-dog" value="woof" />
</labels>
...
</class>
</hibernate-mapping>

Also, I've had another need for what I call "plurals" . This is when the developer is making some reporting page that displays "Here are all your items", or "There are 45 employees in this department" . Typically, the developer starts by testing to see if the quantity is > 1. If so, (s)he adds an "s" on to the end of the business label ("item" becomes "items"). The developer then pats themself on the back but then some executive wants to know why they are looking at a report about "Activitys" instead of "Actvities" . In a perfect world, I'd configure this like so,

<hibernate-mapping>
<class name="org.domain.CustomerItem" table="customer_item">
<labels>
<label locale="en-US" value="Procurement" />
<label locale="de-GE" value="Beschaffung" />
<label locale="clingon" value="askjdfkja#()&&sdfh" />
<label locale="en-dog" value="woof" />
</labels>
<plurals>
<plural locale="en-US" value="Procurements" />
<plural locale="de-GE" value="Beschaffungeb" />
<plural locale="clingon" value="askjdfkja#()&&sdfh())(" />
<plural locale="en-dog" value="woof woofs" />
</plurals>
...
</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 04, 2005 6:24 pm 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
Also, in order to address parsing issues and backwards compatibility, there could be this:

<hibernate-mapping>
<class name="org.domain.CustomerItem" table="customer_item">
<labels xmlns="http://DIFFERENT_NS_THAT_IMPORTS_THE_ORIG.hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<label locale="en-US" value="Procurement" />
<label locale="de-GE" value="Beschaffung" />
<label locale="clingon" value="askjdfkja#()&&sdfh" />
<label locale="en-dog" value="woof" />
</labels>
...
</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 04, 2005 6:36 pm 
Senior
Senior

Joined: Thu May 12, 2005 11:40 pm
Posts: 125
Location: Canada
Why do you feel OR metadata is a good place to put vagaries of presentation?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 04, 2005 6:44 pm 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
Good question. At work, I've built this already - only outside of hibernate. What I end up with is duplication of effort; a bunch of files with the same information in them. For example, I have my hibernate resource file. In it, there are classes that are mapped to tables, and properties that are mapped to columns. Right next door, in the same directory, is an xml file that I have created that maps the same classes to labels, and the same properties to labels. This is good, but not good enough. What happens when the intern refactors a class name, remembers to update the hibernate resource file, but forgets to update the configurations that I am talking about?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 04, 2005 8:08 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Use the <meta> tag and the Configuration API to read it at runtime.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 04, 2005 8:24 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
or make messages.properties , messages_sr_YU.properties etc files with properties like

org.domain.CustomerItem=Procurement
...
and read it with standard ResourceBundle

regards


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 04, 2005 8:28 pm 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
You mean http://www.hibernate.org/hib_docs/api/n ... ibute.html ?

... with

<property ...>
<meta attribute="label">First Name</meta>
</property>

Thanks. I'll pull this to the presentation layer like so:

<prefix:label className="com.domain.Customer" property="firstName" /><br/>
<input type="text" name="Customer.firstName" />


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.