i looking on code created awhile ago, , noticed odd.
i creating persistence unit programmatically due needed user input location of database read.
my code follows
map properties = new hashmap(); db = plan.db; // configure internal eclipselink connection pool properties.put(transaction_type, persistenceunittransactiontype.resource_local.name()); properties.put(jdbc_driver, "net.ucanaccess.jdbc.ucanaccessdriver"); properties.put(jdbc_url, "jdbc:ucanaccess://" + db + ";singleconnection=true;memory=true"); properties.put(jdbc_user, ""); properties.put(jdbc_password, ""); // properties.put( "provider" , "org.eclipse.persistence.jpa.persistenceprovider"); entitymanagerfactory emf2; entitymanager em2; emf2 = persistence.createentitymanagerfactory("pu", properties); em2 = emf2.createentitymanager();
with able create connections multiple times.
the problem noticed had code in "persistence.xml"
<persistence-unit name="pu" transaction-type="resource_local"> <provider>org.eclipse.persistence.jpa.persistenceprovider</provider> <class>db.items</class> <exclude-unlisted-classes>false</exclude-unlisted-classes> <properties> <property name="javax.persistence.jdbc.url" value=""/> <property name="javax.persistence.jdbc.user" value=""/> <property name="javax.persistence.jdbc.driver" value="net.ucanaccess.jdbc.ucanaccessdriver"/> <property name="javax.persistence.jdbc.password" value=""/> </properties>
now noticed cannot find way add "entity class" "persistence unit," able run code fine, this.
i'm curious if overwrites old properies , such persistence unit of same name? still uses persistence class of "db.items."
i want make sure correct way it.
i'm doing changes code, cannot run see if delete in persistence.xml happen, i'm curious this.
i noticed "provider" property commented out. need posted? (it's included in xml file).
there example saw mentioned "server target" being set "no" or something? comments on that?
thanks all
it overwrites properties have specified in persistence.xml
. can example set user name , password in way , other properties used defined in file. if it's "right" way don't know, have done same.
the call persistence.createentitymanager(unit, props)
starts searching named unit
in persistence.xml
found in classpath. properties props
added or overwritten properties read file unit.
i have no comment other questions.
Comments
Post a Comment