Hi,
I have looked hard before posting this, and it seems to me like a trivial thing to fix but I do not know how.
I am using a new beta build of a software named smart fox server (beta 2x) and I was able to make hibernate look like it is working altough I cannot see the tracing to Log4J. My question is twofold :
First I get get a map error when I do the follwing code :
Code:
public void TestHibernateConnexion()
{
Transaction tx = null;
Session session = null;
try
{
session = SessionFactoryUtil.getInstance().getCurrentSession();
}
catch (RuntimeException sessionEx)
{
trace("Getting session Exception : " + sessionEx.getMessage());
return;
}
try
{
tx = session.beginTransaction();
List users = session.createQuery("from User").list();
for (Iterator iter = users.iterator(); iter.hasNext();)
{
User element = (User) iter.next();
trace("found " + element.getEmail());
}
tx.commit();
}
catch (RuntimeException e)
{
if (tx != null && tx.isActive())
{
try
{
// Second try catch as the roll back could fail as well
tx.rollback();
}
catch (HibernateException e1)
{
trace("Error rolling back transaction");
}
// throw again the first exception
throw e;
}
}
}
I have a manager from this tutorial nammed SessionFactoryUtil :
http://www.laliluna.de/articles/first-hibernate-example-tutorial.htmlThis is my annotated class :
Code:
@Entity
@Table(name="lume_user")
public class User {
private long id;
private String email;
private String pswd;
private int type;
@Id
@SequenceGenerator(name="seq_lume_user", sequenceName="lume_seq")
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seq_lume_user")
public long getId() {
return id;
}
public final void setId(long id) {
this.id = id;
}
public String getEmail() {
return email;
}
public final void setEmail(String email) {
this.email = email;
}
public String getPswd() {
return pswd;
}
public final void setPswd(String pswd) {
this.pswd = pswd;
}
public int getType() {
return type;
}
public final void setType(int type) {
this.type = type;
}
}
I get Exception : org.hibernate.hql.ast.QuerySyntaxException Message : User is not mapped [from User].
It is strange because I did a local example with hibernate and everything works. I am confused as to how to force into hibernate an entity class and know for sure it is loaded (any pro advice here is appreciated) Here is the config file for hibernate, I am using a local postgres SQL 9 with the latest postgresql-9.0-801.jdbc4.jar :
Code:
<?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>
<property name="connection.url">jdbc:postgresql://localhost/Lume</property>
<property name="connection.driver_class">org.postgresql.Driver</property>
<property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="connection.username">postgres</property>
<property name="connection.password">xxx123</property>
<property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<!-- thread is the short name for
org.hibernate.context.ThreadLocalSessionContext
and let Hibernate bind the session automatically to the thread
-->
<property name="current_session_context_class">thread</property>
<!-- this will show us all sql statements -->
<property name="hibernate.show_sql">true</property>
<property name="hibernate.id.new_generator_mappings">true</property>
<!-- mapping files -->
<mapping jar="extensions\LumeGame\Lume.jar" />
</session-factory>
</hibernate-configuration>
Ok that is as far as I got and now the second question :
How can I divert the verbose information of hibernate into the log4J already loaded in the java app smartfox server ? There is a log4j.properties here is the content :
Code:
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# An example log4j configuration file that outputs to System.out. The
# output information consists of relative time, log level, thread
# name, logger name, nested diagnostic context and the message in that
# order.
# For the general syntax of property based configuration files see the
# documenation of org.apache.log4j.PropertyConfigurator.
#log4j.rootLogger=DEBUG, fileAppender, consoleAppender
# ConsoleAppender
log4j.appender.consoleAppender=org.apache.log4j.ConsoleAppender
log4j.appender.consoleAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.consoleAppender.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p [%t] %c{2} %3x - %m%n
# SocketAppender
log4j.appender.socketAppender=org.apache.log4j.net.SocketAppender
log4j.appender.socketAppender.remoteHost=localhost
log4j.appender.socketAppender.port=4445
log4j.appender.socketAppender.locationInfo=true
# Regular FileAppender
log4j.appender.fileAppender=org.apache.log4j.DailyRollingFileAppender
log4j.appender.fileAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.fileAppender.File=logs/smartfox.log
log4j.appender.fileAppender.layout.ConversionPattern=%d{dd MMM yyyy HH:mm:ss,SSS} %-5p [%t] %c{3} %3x - %m%n
log4j.appender.fileAppender.Encoding=UTF-8
# BootLogger FileAppender(s)
log4j.appender.bootFileAppender=org.apache.log4j.DailyRollingFileAppender
log4j.appender.bootFileAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.bootFileAppender.File=logs/boot/boot.log
log4j.appender.bootConsoleAppender.threshold=DEBUG
log4j.appender.bootFileAppender.layout.ConversionPattern=%d{dd MMM yyyy HH:mm:ss,SSS} %-5p [%t] %c{3} %3x - %m%n
log4j.appender.bootFileAppender.Encoding=UTF-8
log4j.appender.bootConsoleAppender=org.apache.log4j.ConsoleAppender
log4j.appender.bootConsoleAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.bootConsoleAppender.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p [%t] %c{3} %3x - %m%n
log4j.appender.bootConsoleAppender.threshold=WARN
# ConversionPattern=%-4r %-5p [%t] %37c %3x - %m%n
# The file is rolled over very day
# '.'yyyy-MM-dd-HH rolls every hour
# '.'yyyy-MM-dd-HH-mm rolls every minute
log4j.appender.fileAppender.DatePattern ='.'yyyy-MM-dd-HH
# log4j.category.com.smartfoxserver.v2=DEBUG,consoleAppender,fileAppender,socketAppender
log4j.category.com.smartfoxserver=INFO,consoleAppender,fileAppender
log4j.category.sfs.test=INFO,consoleAppender,fileAppender
log4j.category.bootLogger=DEBUG,bootFileAppender,bootConsoleAppender
log4j.category.sfs2x=DEBUG,consoleAppender,fileAppender
log4j.category.Extensions=DEBUG,consoleAppender,fileAppender
I am trying what I can to also list the loaded entities from hibernate and use the tracing functions inside smartfox to be able to see, right now its really hard to pin point the problem and I am a little too newb with all these libs, any help on any part of the two questions would be greatly appreciated for my sanity :)