• Post Reply Bookmark Topic Watch Topic
  • New Topic

Entity bean and database table  RSS feed

 
Naveen Sampra
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone help me with this.
How can I find out within my entity bean(programmatically), the database table that the bean maps to.
Specifically, I want to find out the table name.
~Naveen
 
Dana Hanna
Ranch Hand
Posts: 227
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'll assume that you are talking about CMP... There is no official way to do that, and I'm not sure how you'd do it unofficially. What exactly are you trying to accomplish? Maybe if we had an idea of the big picture, we could help.
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cant you parser vendor specific DD?
 
Chris Mathews
Ranch Hand
Posts: 2712
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Pradeep Bhat:
Cant you parser vendor specific DD?

The deployment descriptor is not made available at runtime. I guess you could go around cracking open ejb-jars but that would be nothing but a dirty hack. Like Dana said, there is no standard way to do this nor do I really see a point in it.
 
Naveen Sampra
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I am the original poster.
Yes, I am talking about a CMP.
Here is the reason why I need to find out the corresponding table name.
When my CMP modifies it's underlying persistant data, I need to fire off a notification message informing what table,columns were affected. This message is put on a JMS queue. I have a listener on another server that reads this message and updates a remote DB( which is a copy of the DB that the CMP was working on). In short I am trying to replicate the same transaction that the CMP executed.
I can kick-off the notification logic from the ejbStore() method, but I need to know the table name and column names of underlying DB table.
~Naveen
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The deployment descriptor is not made available at runtime

Why? Is it mentioned in the spec?
[ September 03, 2003: Message edited by: Pradeep Bhat ]
 
Chris Mathews
Ranch Hand
Posts: 2712
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Naveen Sampra:
When my CMP modifies it's underlying persistant data, I need to fire off a notification message informing what table,columns were affected. This message is put on a JMS queue. I have a listener on another server that reads this message and updates a remote DB( which is a copy of the DB that the CMP was working on). In short I am trying to replicate the same transaction that the CMP executed.

Most commercial RDBMS systems support replication and have for years. Your problem would be much better solved (both in terms of reliability, performance, and time) by delegating this functionality to the database.
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a look at this
http://otn.oracle.com/oramag/oracle/03-sep/o53devtrends.html
I have not yet read this, may be it helps you.
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The deployment descriptor is not made available at runtime. I guess you could go around cracking open ejb-jars but that would be nothing but a dirty hack. Like Dana said, there is no standard way to do this nor do I really see a point in it.

Disclaimer: I agree with Dana and Chris about the act of reading the actual table name being a somewhat suspicious thing to do.
But. I think you should get an InputStream for anything under WEB-INF using Class#getResourceAsStream(String)?
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://java.sun.com/PrintPage.jsp?url=http%3A//java.sun.com/blueprints/qanda/ejb_tier/restrictions.html
From Sun site
Read-only data can, however, be stored in files in a deployment JAR, and accessed with the getResource() or getResourceAsStream() methods of java.lang.Class.
This should allow me to access the DD as well.
[ September 03, 2003: Message edited by: Pradeep Bhat ]
 
Tejpal Singh
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Naveen Sampra:

When my CMP modifies it's underlying persistant data, I need to fire off a notification message informing what table,columns were affected. This message is put on a JMS queue. I have a listener on another server that reads this message and updates a remote DB( which is a copy of the DB that the CMP was working on). In short I am trying to replicate the same transaction that the CMP executed.
I can kick-off the notification logic from the ejbStore() method, but I need to know the table name and column names of underlying DB table.

Naveen if it is that necessary, you may consider keeping the mapping of entity beans with database tables in another DB table say Entity_Table_Map.
You can then query this table to get the specific table name for the invoking bean.
Form this table name you can get the MetaData information as required.
Then you may trigger your notification routine containing above table info.
Its a work around for your problem, you can improvise on the above logic as per your requirements.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!