-->
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.  [ 15 posts ] 
Author Message
 Post subject: JBoss AS 4.0.4. & Hibernate 3 as MBean & Annotation
PostPosted: Thu Feb 01, 2007 12:51 pm 
Newbie

Joined: Thu Feb 01, 2007 12:32 pm
Posts: 9
Location: Belgrade, Serbia
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.2.2. GA

Mapping documents:
package com.edg.telebet.common.transport;

import com.edg.telebet.common.TelebetSettings;
import javax.persistence.*;

@Entity
@Table (name="languagestring")
public class LanguageString extends TelebetSettings implements java.io.Serializable{

//public static final long serialVersionUID = 15L;

public LanguageString() {
}
public LanguageString(Long stringValuesId, Long languageId,String stringValue){
this.stringValue = stringValue;
this.languageId = languageId;
this.stringValuesId = stringValuesId;
}

public Long stringValuesId;
public Long languageId;
public String stringValue;
public Long getStringValuesId() {
return stringValuesId;
}
public void setStringValuesId(Long stringValuesId) {
this.stringValuesId = stringValuesId;
}
public void setLanguageId(Long languageId) {
this.languageId = languageId;
}
public Long getLanguageId() {
return languageId;
}
public void setStringValue(String stringValue) {
this.stringValue = stringValue;
}
public String getStringValue() {
return stringValue;
}
public String toString() {
return stringValue;
}

}



Code between sessionFactory.openSession() and session.close():
InitialContext ctx = null;
try {
ctx = new InitialContext();
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
SessionFactory factory = null;
try {
factory = (SessionFactory)
ctx.lookup("java:/hibernate/SessionFactory");
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Session hsession = factory.openSession();
hsession.getTransaction().begin();


int sizeOfList = hsession.createQuery("from languagestring ls").list().size();
TLog.logConsole("LanguageString has "+ sizeOfList +" elements.");


Full stack trace of any exception that occurs:
17:43:57,108 ERROR [Scheduler$Listener] Handling a Scheduler call failed
org.hibernate.hql.ast.QuerySyntaxException: languagestring is not mapped [from languagestring ls]
at org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:158)
at org.hibernate.hql.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:87)
at org.hibernate.hql.ast.tree.FromClause.addFromElement(FromClause.java:70)
at org.hibernate.hql.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:267)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3049)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:2938)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:688)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:544)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:281)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:229)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:227)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:159)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:110)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:71)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1612)
at com.edg.telebet.cs.server.StartCSServer.perform(StartCSServer.java:143) << CLASS THAT CALLS HIBERNATE
at org.jboss.varia.scheduler.Scheduler$Listener.handleNotification(Scheduler.java:1235)
at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.jboss.mx.notification.NotificationListenerProxy.invoke(NotificationListenerProxy.java:153)
at $Proxy10.handleNotification(Unknown Source)
at javax.management.NotificationBroadcasterSupport.handleNotification(NotificationBroadcasterSupport.java:257)
at javax.management.NotificationBroadcasterSupport$SendNotifJob.run(NotificationBroadcasterSupport.java:322)
at javax.management.NotificationBroadcasterSupport$1.execute(NotificationBroadcasterSupport.java:307)
at javax.management.NotificationBroadcasterSupport.sendNotification(NotificationBroadcasterSupport.java:229)
at javax.management.timer.Timer.sendNotification(Timer.java:1234)
at javax.management.timer.Timer.notifyAlarmClock(Timer.java:1203)
at javax.management.timer.TimerAlarmClock.run(Timer.java:1286)
at java.util.TimerThread.mainLoop(Timer.java:512)
at java.util.TimerThread.run(Timer.java:462)



Name and version of the database you are using:
RDBMS: Oracle, version: Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.1.0 - Production


The generated SQL (show_sql=true): don't have

Debug level Hibernate log excerpt: don't have

MBean configuration:
<mbean code="org.jboss.hibernate.jmx.Hibernate"
name="jboss.har:service=Hibernate">

<depends>jboss:service=Naming</depends>
<depends>jboss:service=TransactionManager</depends>
<depends>jboss.jca:service=DataSourceBinding,name=OracleDS</depends>
<depends>jboss.cache:service=TreeCache</depends>

<attribute name="DatasourceName">java:OracleDS</attribute>
<attribute name="Username">******</attribute>
<attribute name="Password">******</attribute>
<attribute name="Dialect">org.hibernate.dialect.Oracle9Dialect</attribute>
<attribute name="SessionFactoryName">java:/hibernate/SessionFactory</attribute>

<attribute name="CacheProviderClass">org.jboss.hibernate.cache.DeployedTreeCacheProvider</attribute>
<attribute name="DeployedTreeCacheObjectName">jboss.cache:service=TreeCache</attribute>

<attribute name="ShowSqlEnabled">true</attribute>

</mbean>


Problems with Session and transaction handling?
Yes

Is there any possible way of mapping existing class in Hibernate, and not using HAR files under JBOSS deploy folder and how? This error always occurs when I tried to use "mapped" class LanguageString (event when I used explicit settings for TABLE and COLUMN).

Thank you for your answers.

Drazen Krsmanovic

Read this: http://hibernate.org/42.html


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 01, 2007 1:23 pm 
Senior
Senior

Joined: Tue Jul 25, 2006 9:05 am
Posts: 163
Location: Stuttgart/Karlsruhe, Germany
Hi,

try changing the following
Quote:
int sizeOfList = hsession.createQuery("from languagestring ls").list().size();


To the following
Code:
int sizeOfList = hsession.createQuery("from LanguageString ls").list().size();


always select from the Entity (i think it is case sensitive) and not the value in @Table


Thanks,

Andy

_________________
Rules are only there to be broken


Top
 Profile  
 
 Post subject: Didn't solve the problem...
PostPosted: Fri Feb 02, 2007 4:45 am 
Newbie

Joined: Thu Feb 01, 2007 12:32 pm
Posts: 9
Location: Belgrade, Serbia
Unfortunately changing "languagestring" into "LanguageString" didn't solve the problem. Anyway thanx for your help. :-)

Drazen


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 02, 2007 6:09 am 
Senior
Senior

Joined: Tue Jul 25, 2006 9:05 am
Posts: 163
Location: Stuttgart/Karlsruhe, Germany
Hi,

Are you deploying on some kind of App Server ? If so how are you deploying the application (File structure)

Cheers,

Andy

_________________
Rules are only there to be broken


Top
 Profile  
 
 Post subject: JBoss Application Server 4.0.4.
PostPosted: Fri Feb 02, 2007 7:20 am 
Newbie

Joined: Thu Feb 01, 2007 12:32 pm
Posts: 9
Location: Belgrade, Serbia
Hi,

Yes, application server is JBoss Application Server 4.0.4.

There is one Enterprise Archiver (EAR) in <jboss as root folder>/server/deploy/ where is JAR file with classes, properties and XML files, and META-INF folder with application.xml.

Inside mentioned JAR file there is META-INF folder, where file hibernate.cfg.xml is placed:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="java:/hibernate/SessionFactory">
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.password">******</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@********:*****:TESTDB<host>:<port1521>:<sid></property>
<property name="hibernate.connection.username">*******</property>
<property name="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</property>
<!-- List of annotaded classes -->
<mapping class="com.edg.telebet.common.transport.LanguageString"/>
</session-factory>
</hibernate-configuration>

Bye,
Drazen


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 02, 2007 7:36 am 
Senior
Senior

Joined: Tue Jul 25, 2006 9:05 am
Posts: 163
Location: Stuttgart/Karlsruhe, Germany
Hi,

I have just looked over your entity code again, and noticed 2 things:

1) You are using inheritance, what strategy are you using ? Could you also post the code for the parent entity

2) You have no @Id, i assume you have this in the parent class ?

Also in your hibernate.cfg.xml file you only seem to map the subclass and not the parent, depending on your inheritance startegy this might be a problem.

Cheers,

Andy

_________________
Rules are only there to be broken


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 02, 2007 7:37 am 
Senior
Senior

Joined: Tue Jul 25, 2006 9:05 am
Posts: 163
Location: Stuttgart/Karlsruhe, Germany
Hi,

I have just looked over your entity code again, and noticed 2 things:

1) You are using inheritance, what strategy are you using ? Could you also post the code for the parent entity

2) You have no @Id, i assume you have this in the parent class ?

Also in your hibernate.cfg.xml file you only seem to map the subclass and not the parent, depending on your inheritance startegy this might be a problem.

Cheers,

Andy

_________________
Rules are only there to be broken


Top
 Profile  
 
 Post subject: commented out TelebetSettings
PostPosted: Fri Feb 02, 2007 7:53 am 
Newbie

Joined: Thu Feb 01, 2007 12:32 pm
Posts: 9
Location: Belgrade, Serbia
HI,

1. I have just commented out parent class TelebetSettings, and the error still remains. TelebetSettings is not needed to be perisistent, it just has some internal flags.

2. Well I don't have id, because i just wanted to test hibernate and to load table entries. Although LanguageString has composite key consisted of languageId, stringValuesId. Before posting on this forum I have created Primary Key class that would be @Id for LanguageString but it didn't worked either.

3. Yes I mapped only LanguageString, because TelebetSettings is not ment to be persistante.

Problem remains how to persuade Hibernate to at least read class that I want to be mapped... :-\

Thanx,
Drazen

_________________
Drazen


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 02, 2007 10:16 am 
Senior
Senior

Joined: Tue Jul 25, 2006 9:05 am
Posts: 163
Location: Stuttgart/Karlsruhe, Germany
Hi,

Do you run the hbm2ddl task on deployment ? if you do does it create the correct schema in the database ??

Try adding the following line to the
<property name="hibernate.hbm2ddl.auto">create-drop</property>

I imagine it will give you some exceptions, hopefully these will be more useful than "languagestring is not mapped"

Andy

_________________
Rules are only there to be broken


Top
 Profile  
 
 Post subject: No Luck My Friend
PostPosted: Fri Feb 02, 2007 10:37 am 
Newbie

Joined: Thu Feb 01, 2007 12:32 pm
Posts: 9
Location: Belgrade, Serbia
Hi again,

Well, I did as you told me to, and hibernate didn't became any more descriptiv as it was till now. Looked in JBOSS AS log folder, log4j log file, and console, and nothing new. Anyway thank you very much for your help. :-)

Drazen

_________________
Drazen


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 02, 2007 10:51 am 
Senior
Senior

Joined: Tue Jul 25, 2006 9:05 am
Posts: 163
Location: Stuttgart/Karlsruhe, Germany
but did it try and create the schema for the entity ?? If so was it exactly the same error ? as in my experience it is never going to be a querySyntaxException but a Annotation or Mapping exception.

_________________
Rules are only there to be broken


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 02, 2007 10:59 am 
Newbie

Joined: Thu Feb 01, 2007 12:32 pm
Posts: 9
Location: Belgrade, Serbia
I guess it didn't create the schema.

I created XML map file for class and it did changed error, some ORA-XXXX error, so this way hibernate does work....

_________________
Drazen


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 02, 2007 11:12 am 
Newbie

Joined: Thu Feb 01, 2007 12:32 pm
Posts: 9
Location: Belgrade, Serbia
After making XML file it did make schema .... it droped and created the table. :-) (and in process killing all my data)

_________________
Drazen


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 02, 2007 12:11 pm 
Senior
Senior

Joined: Tue Jul 25, 2006 9:05 am
Posts: 163
Location: Stuttgart/Karlsruhe, Germany
change this config setting

Code:
<property name="hibernate.hbm2ddl.auto">create-drop</property>


to

Code:
<property name="hibernate.hbm2ddl.auto">update</property>


It will make it create it, but on shutdown it will not destroy/drop it.

Andy

_________________
Rules are only there to be broken


Top
 Profile  
 
 Post subject: I managed to do what I wanted
PostPosted: Fri Feb 02, 2007 2:19 pm 
Newbie

Joined: Thu Feb 01, 2007 12:32 pm
Posts: 9
Location: Belgrade, Serbia
Hi,

I have loaded data from database into List<LanguageString> with help of *.hbm.xml file that was put inside of Hibernate Archive (HAR).

Thank you again andydale for your help. :-)

See you around on this forum.

_________________
Drazen


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 15 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.