I get an unusual problem.
My J2EE application is based on JBOSS 4.0.3.
I used EJB3 with entity beans with JBOSS default database HSQL, everything was working ok.
I decided a few days ago to move to another database: SQL Server 2005.
The only problem I found is with the named query. The query is not found if it is defined
in the POJO class as it was previously.
From the documentation, it is possible to define the named query in the class.
What could be different from those two configurations ???
Error from JBOSS 4:
org.hibernate.MappingException: Named query not known: alert_findAllUsers
Class Alert.java
@Entity
@Table(name = "alert")
@NamedQuery(
name = Alert.FIND_ALL_USERS,
query = "select distinct a.userId from Alert a"
)
public class Alert implements Serializable {
public static final String FIND_ALL_USERS = "alert_findAllUsers";
........
}
Session Bean UserAlertBean
/**
* Find all alert objects.
* @return the Alert object
*/
public final Collection < Alert > findAllUsers() {
return manager.createNamedQuery(Alert.FIND_ALL_USERS).getResultList();
}
Fichier Alert.hbm.xml
<hibernate-mapping>
<class name="com.monitor.ejb.alert.Alert" table="alert">
<id name="id" type="long" column="id" >
<generator class="increment"/>
</id>
<property name="message">
<column name="message" sql-type="char(2000)" not-null="true"/>
</property>
<property name="userId">
<column name="userId" sql-type="char(10)" not-null="true"/>
</property>
</class>
</hibernate-mapping>
Fichier persistence.xml
<persistence>
<persistence-unit name="alerts">
<jta-data-source>java:/MSSQLDS</jta-data-source>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect" />
<property name="hibernate.case.use_query_cache" value="true" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.connection.datasource" value="java:/MSSQLDS"/>
</properties>
</persistence-unit>
</persistence>
|