Open senthilboopathi opened 8 years ago
@branaway Can we have your say on this, please? More interested to know your suggestion than your fix.
Sorry I missed your note. I'll take a look at the issue soon.
@branaway Thanks a lot for your attention.
A couple of things:
db_default.url=jdbc:h2:mem:student db_default.driver=org.h2.Driver db_default.user=sa db_default.pass=
db_teacher.url=jdbc:h2:mem:teacher db_teacher.driver=org.h2.Driver db_teacher.user=sa db_teacher.pass=
JPA is supported in general. There might be some quirks. Let me know your use case.
Thanks.
@branaway Many thanks for your note. On Monday we will provide the source that was having jpa issue. Thanks again
btw, there is issues with the mailer instrumentation, so email sending is not working yet. This would affect the multi-DB sample.
@branaway Thanks for the note. Will check accordingly.
@branaway This is the sample code of JPAConfigItem.java
package libs.modules.config.src.play.modules.config.models;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.*;
import play.Logger;
import play.db.jpa.GenericModel;
import play.db.jpa.JPQL;
import play.modules.scaffold.ScaffoldingIgnore;
import libs.modules.config.src.play.modules.config.ConfigPlugin;
/**
* Default {@link IConfigItem} implementation on JPA
*
*/
@Entity
@Table(name = "Conf")
@ScaffoldingIgnore
public class JPAConfigItem extends GenericModel implements IConfigItem {
/**
*
*/
private static final long serialVersionUID = -8415264008115090076L;
@Id @GeneratedValue(strategy = GenerationType.SEQUENCE)
public Long id;
public String name;
public String value;
public JPAConfigItem() {
}
private JPAConfigItem(String key, String value) {
this.name = key;
this.value = value;
}
@Override
public String pc_key() {
return name;
}
@Override
public String pc_value() {
return value;
}
@Override
public IConfigItem pc_value(String value) {
this.value = value;
return this;
}
public IConfigItem pc_save() {
try{
return (IConfigItem) save();
} catch(Exception e){
e.printStackTrace();
return (IConfigItem) null;
}
}
@Override
public String toString() {
return String.format("%1$s=%2$s", name, value);
}
@SuppressWarnings("unchecked")
@Override
public List<IConfigItem> pc_all() {
List<IConfigItem> l = new ArrayList<IConfigItem>();
List<JPAConfigItem> l0 = JPQL.instance.findBy(
JPAConfigItem.class.getName(), "order by name", new Object[] {});
for (JPAConfigItem ci : l0) {
l.add(ci);
}
return l;
}
@Override
public IConfigItem pc_new(String key, String value) {
ConfigPlugin.assertValidKey(key);
return new JPAConfigItem(key, value);
}
@Override
public IConfigItem pc_findByKey(String key) {
try {
Object[] o = new Object[1];
o[0] = key;
return (IConfigItem) JPQL.instance.findOneBy(
JPAConfigItem.class.getName(), "name", o);
} catch (Exception e) {
Logger.warn(e, "Error fetch configuration item by key: %1$s", name);
return null;
}
}
@Override
public void pc_clear() {
JPQL.instance.deleteAll(JPAConfigItem.class.getName());
}
@Override
public void pc_delete() {
delete();
}
}
Got that. Since I'm in a hurry, can you test it out with my release in the "releases" menu?
Laptop not handy, but I recommend you put your entity in models package or sub packages. Models must reside in the designated package.
can you try:
List<JPAConfigItem> fetch = find("order by name", new Object[] {}).fetch();
// or
List<JPAConfigItem> findBy = (List<JPAConfigItem>) getJPAConfig(getClass()).jpql.findBy(JPAConfigItem.class.getName(), "order by name", null);
in your own sample code?
@branaway Thanks for spending time and I tried with
List<JPAConfigItem> fetch = find("order by name", new Object[] {}).fetch();
and its working fine.
1. I tried to install jdk8 version and run "forum" sample script, and I tried to register and it gets some Oops error and I click Users link http://localhost:9000/users and getting following error:
JPAQueryException occured : Error while executing query from User: org.hibernate.InstantiationException: No default constructor for entity: models.User
JPA error A JPA error occurred (Found Entity-class (models.Student) referring to none-existing JPAConfig (jpa config name: default). Is JPA properly configured?):
Compilation error The file /app/libs/modules/config/src/play/modules/config/models/JPAConfigItem.java could not be compiled. Error raised is : Type mismatch: cannot convert from List<capture#1-of ? extends GenericModel> to List
In /app/libs/modules/config/src/play/modules/config/models/JPAConfigItem.java (around line 79) 79: JPAConfigItem> l0 = JPQL.instance.findBy( 80: JPAConfigItem.class.getName(), "order by name", new Object[] {});
Let me know jdk8 branch supports JPA??
Note: Branch: jdk8 https://github.com/branaway/play/tree/jdk8 My java version: java version "1.8.0_25"
Thanks for Advance