Showing posts with label EJB. Show all posts
Showing posts with label EJB. Show all posts

Thursday, October 29, 2009

EJB entity relations onetomany

Using @OneToMany and @ManyToOne entity relationship might sound little difficult and confusing in the beginning but actually it is very easy. I recently used it in one of my projects and it worked great.

Here is how the code in your entities should look like...

Assuming table 1 and table 2 have one to many relationship...then...

in the table 1 entity...you have...

...
    @OneToMany(mappedBy="table2mapping")
    private Collection table2list;
   ..associated getter and setter...


in the table2 entity..you have...
@JoinColumn(name = "table2ID", referencedColumnName = "table1ID", insertable=false, updatable=false)
    @ManyToOne
    private table1 table2mapping;

@JoinColumn should be changed depending upon your requirements...
Let me know if you have any questions...

Read more...

Friday, October 9, 2009

Multiple Persistence Units in JAVA EE project

Hello All,

If you are trying to create multiple persistence units in your JAVA EE project...the below is how you do it...I recently had to do this for one of my projects and it worked great...

Persistence.xml should look like below



  
    provideryouareusing
    jdbc/db1
    entity.entity1
    entity.entity2
    true
    
    
  
  
    jdbc/db2
    entity.entity3
    true
    
  


In the entity manager bean class you have to clearly specify which PU is the entity using...something like shown below...

@PersistenceContext(unitName="PUname")

let me know if you have any questions...

Read more...

About This Blog

In this blog you will find simple but great ideas on various topics ranging from food recipes to investment strategies. I hope the ideas presented in this blog will help you all in some way or other. Also included are the recent and hot news around the world...

Go ahead and grasp my ideas...

Disclaimer and Terms of Use

All the ideas and opinions provided herein are intended to share and inform simple and useful information. They come with no warranty of any kind. If you should choose to interpret graspmyideas.blogspot.com information as perfect working ideas, or advice or if you want to completely rely on these ideas, you do so at your own risk.

This site is offered as is and without warranties of any kind. We are not responsible for timeliness, accuracy, unavailability or interruptions in availability, viruses or other defects in the site or its contents. In no event shall graspmyideas.blogspot.com site or its authors are responsible for any damages to users or their computer systems.


Your Ad Here

  © Blogger template AutumnFall by Ourblogtemplates.com 2008

Back to TOP