Results 1 to 7 of 7
- 03-23-2010, 03:00 PM #1
Member
- Join Date
- Mar 2010
- Posts
- 11
- Rep Power
- 0
"Dynamic" Java Annotations - possible?
Hi everybody!!
Not sure if that is even a question that makes sense, it definately does for me.
I have a hibernate entity (so a pojo with annotations), which though only reads from the database and in this particular case does not read from a table, but from a function (postgresql).
The Hibernate annotation goes like this:
@Entity
@Table(name="get_report_entity('T')")
public class ReportEntity extends BaseEntity
{...}
As you can see the sql function (stored procedure) is "get_report_entity('T')". Now my problem - the 'T' as the parameter stands for "Test mode". And in production this should change to a 'P'.
So the question is - is there a way for me to make that 'T' configurable, ie change that from the outside without having to recompile the whole code?? So ideally access an environment variable or a config file or something...
Or do I have to switch to an xml mapping...p l e a s e n o t!
Thanks very much!!
Cheers,
CC
- 03-23-2010, 03:06 PM #2
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
- 03-23-2010, 03:22 PM #3
Member
- Join Date
- Mar 2010
- Posts
- 11
- Rep Power
- 0
Ok, thanks very much!
Can I ask you (on your opinion on) one to two more question related to the above:
(Sry, I know I can and will read this up, but as u are so quick) Is it possible to mix xml mapping and annotations, ie have the fieldmappings defined as annotations, and the table mappings in the xml?
If not -
What would you think of the solution of having a baseclass (class ReportEntity) without any hibernate table-annotation, and from it extend two empty child classes (class ReportEntityProd and class ReportEntityTest), and then use a factory to create the ReportEntity class which in turn uses a config file to choose whether to instantiate ReportEntityProd.class or ReportEntityTest.class. Does that make sense, or would that mess up hibernate internally??
Very much appreciated!
Cheers,
CC
- 03-23-2010, 04:59 PM #4
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
XML can be mixed annotations. XML information overrides annotations when a conflict occurs.
You should not have dev specific classes deployed together with your production code on your production environment. Those database settings are much like the information you provide in your datasource xml file in your server's deploy so that should go into an xml file as well.
- 03-23-2010, 05:20 PM #5
Member
- Join Date
- Mar 2010
- Posts
- 11
- Rep Power
- 0
Thanks!
Thats what I ll do then, keep the field definitions in the java file (for now), and the table mappings in the xml!
Cheers!
btw, its a Desktop Environment (ie a Swing/Jide based app), hibernate still works like a charm though!
- 03-23-2010, 05:21 PM #6
Member
- Join Date
- Mar 2010
- Posts
- 11
- Rep Power
- 0
ps.: Thanks for the very quick replies
- 03-23-2010, 05:27 PM #7
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
Similar Threads
-
Java, Military Format using "/" and "%" Operator!!
By sk8rsam77 in forum New To JavaReplies: 11Last Post: 02-26-2010, 03:03 AM -
Runtime error "Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
By shantimudigonda in forum New To JavaReplies: 1Last Post: 11-20-2009, 07:58 PM -
[SOLVED] pls help :S . "Exception in thread "AWT-EventQueue-0" java.lang.NullPointerE
By ara in forum New To JavaReplies: 10Last Post: 01-29-2009, 08:00 AM -
MoneyOut.println("It took you (whats wrong?>",year,"<WW?) years to repay the loan")
By soc86 in forum New To JavaReplies: 2Last Post: 01-24-2009, 06:56 PM -
the dollar sign "$", prints like any other normal char in java like "a" or "*" ?
By lse123 in forum New To JavaReplies: 1Last Post: 10-20-2008, 07:35 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks