-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: JBOSS and named query problem
PostPosted: Thu Oct 05, 2006 3:13 am 
Newbie

Joined: Thu Oct 05, 2006 2:42 am
Posts: 2
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>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 05, 2006 9:55 am 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
There is no named query in xml.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 05, 2006 1:41 pm 
Newbie

Joined: Thu Oct 05, 2006 2:42 am
Posts: 2
I agree there is no named query in the xml file ... I thought the annotations in the entity class would be enough.

From the Hibernate documentation:
You can map EJBQL/HQL queries using annotations. @NamedQuery and @NamedQueries can be defined at the class level OR in a JPA XML file

In my example, the entity holds the named query.
Is it mandatory to add the named query in the xml file?
I know this way it will work, but why not with the pojo class ?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 06, 2006 3:36 am 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
Are you having both - xml and annotation in the classpath?
Use just one of them - with named query init.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.