The Artima Developer Community
Sponsored Link

Java Answers Forum
Multiple persistence Unit

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Tanvir Hossain

Posts: 53
Nickname: tanvirtonu
Registered: Feb, 2006

Multiple persistence Unit Posted: Jul 7, 2009 3:58 PM
Reply to this message Reply
Advertisement
I m new in java persistence api. I have made an application with netbeans6.5 using JPA.Now I m running well with one database but i need to use more database schemas in my application.How can I dynamically change my persistence unit at run time.SO that it starts with a perticular persistence unit that i want.I m using mysql and toplink persistence provider.I just need to change my database schema name in my persistence unit file.Every other details are same.Now, If I want to make a java bean to set the name of persistenceUnit at startup and that beans will be bound to my entity manager in my application, am I on the right way to do this? The problem is that I made that bean but the entity manager is not getting the persistenceUnit name at runtime.I m posting the bean for setting up my persistenceUnit name.Pls help me.
package saraelectro;
import java.beans.*;
import java.io.Serializable;
 
/**
 *
 * @author Administrator
 */
public class myBean implements Serializable {
 
    public static final String PROP_SAMPLE_PROPERTY = "sampleProperty";
 
    private String sampleProperty;
 
    private PropertyChangeSupport propertySupport;
 
    public myBean() {
        propertySupport = new PropertyChangeSupport(this);
    }
 
    public String getSampleProperty() {
        return sampleProperty;
    }
 
    public void setSampleProperty(String value) {
        String oldValue = sampleProperty;
        sampleProperty = value;
        propertySupport.firePropertyChange(PROP_SAMPLE_PROPERTY, oldValue, sampleProperty);
    }
 
 
    public void addPropertyChangeListener(PropertyChangeListener listener) {
        propertySupport.addPropertyChangeListener(listener);
    }
 
    public void removePropertyChangeListener(PropertyChangeListener listener) {
        propertySupport.removePropertyChangeListener(listener);
    }
 
}

Now the code that netbeans creted for binding the bean to entity manager-
bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

saraelectroPUEntityManager =
java.beans.Beans.isDesignTime() ? null : javax.persistence.Persistence.createEntityManagerFactory(myBean1.getSampleProperty()).createEntityManager();

Topic: A quanstion about generics Previous Topic   Next Topic Topic: package statement

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use