DB Config:
db=mysql://root@localhost/db
jpa.dialect=org.hibernate.dialect.MySQLDialect
....
db_other.url=jdbc:mysql://localhost/db2
db_other.driver=com.mysql.jdbc.Driver
db_other.user=root
db_other.pass=
db_other.jpa.dialect=org.hibernate.dialect.MySQLDialect
In these databases i have absolutely exact tables (clones). But the difference is that there's different values in these tables. ('Value #1' and 'Value #2' respectively).
A simple model:
package models;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.PersistenceUnit;
import javax.persistence.Table;
import play.db.jpa.GenericModel;
@Entity
@PersistenceUnit(name="other")
@Table(name="testtable")
public class DbTest extends GenericModel {
@Id
public String value;
}
the rest of code:
List<DbTest> lst = DbTest.findAll();
if(!lst.isEmpty())
System.out.println(lst.get(0).value);
It always prints Value #1. (It must be 'Value #2' as it's in db2). Surely, i've specified @PersistenceUnit(name="other"). But that doesn't have any effect. Even if i change name of pers.unit to random, no any errors. This annotation is not working or just being ignored? Or i did mistake somewhere? :/
p.s Also, i've tried to get the EntityManager as it's shown in the framework manual (/documentation/jpa#multiple).
EntityManager em = JPA.getJPAConfig("other").em();
But it's not possible: << The method getJPAConfig(String) is undefined for the type JPA >>