Im trying to retrieve data from an SQL Server 2008 database , i get data when i run this code:
JPA.em("default").find(IpDescription.class, 1);
This returns the object IpDescription populated with data from the database.
But when i run this code:
JPA.em("default").createQuery("from IpDescription",IpDescription.class);
It gives the following error;
java.lang.NoSuchFieldError: NONE
at org.hibernate.ejb.QueryImpl.<init>(QueryImpl.java:615)
at org.hibernate.ejb.QueryImpl.<init>(QueryImpl.java:76)
at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:286)
Any Ideas?
Thanks in advanced.
-----------------------------------------
application,conf
db.default.driver=com.microsoft.sqlserver.jdbc.SQLServerDriver
db.default.url="jdbc:sqlserver://localhost\\SQLEXPRESS:1433;databasename=xxxx;user=xxx;password=xxxx;"
db.default.jndiName=DefaultDS
# You can expose this datasource via JNDI if needed (Useful for JPA)
jpa.default=defaultPersistenceUnit
----------------------------------------
Build.scala
val main = PlayProject(appName, appVersion, appDependencies, mainLang = JAVA).settings(
// Add your own project settings here
ebeanEnabled := false
)
------------------------------------------
persistence.xml
version="2.0">
<persistence-unit name="defaultPersistenceUnit" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<non-jta-data-source>DefaultDS</non-jta-data-source>
<properties>
<!-- <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/> -->
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
<property name="hibernate.show_sql" value="true"/>
</properties>
</persistence-unit>
</persistence>
-----------------------
IpDescription.java
@Entity
@Table(name="IpDescription")
public class IpDescription extends Model {
@Id
@GeneratedValue
public Integer idIp;
public String ip;
public String lasteditiondate;
public String actualdate;
public String description;
public String author;
public static IpDescription findById(String idIp) {
return JPA.em().find(IpDescription.class, idIp);
}
public static Finder<Integer,IpDescription> find = new Finder(
Integer.class, IpDescription.class
);
public static List<IpDescription> all() {
return find.all();
}
/**
* Update this IpDescription.
*/
public void update(Long id) {
JPA.em().merge(this);
}
/**
* Insert this new IpDescription.
*/
public void save() {
JPA.em().persist(this);
}
/**
* Delete this IpDescription.
*/
public void delete() {
JPA.em().remove(this);
}