-->
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.  [ 10 posts ] 
Author Message
 Post subject: Hibernater / MySQL - using MyEclipse
PostPosted: Sat Jun 24, 2006 6:45 pm 
Newbie

Joined: Sat Jun 24, 2006 6:26 pm
Posts: 10
Hello!

Having a pretty simple user-table in a mysql-database.
Beeing able to add users to the table - that is working.
but not reading the users back and list them.
Getting the following error:
Quote:
00:13:20,296 INFO SessionFactoryImpl:379 - Checking 0 named queries
00:13:20,468 ERROR PARSER:35 - *** ERROR: line 1:6: unexpected token: is org.hibernate.hql.ast.QuerySyntaxError: unexpected token: is near line 1, column 6 [from is.in.domain.Player] at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:63)


using this link as a 'template' for understanding this, might probably be a better 'tutorial' out there.
http://www.laliluna.de/download/struts-hibernate-integration-tutorial-en.pdf
using mysql 5.1.

this is my table:
Code:
CREATE TABLE `player` (
  `idPlayer` int(10) unsigned NOT NULL auto_increment,
  `firstname` varchar(45) default NULL,
  `lastname` varchar(45) default NULL,
  `hcp` float default NULL,
  `number` varchar(12) default NULL,
  PRIMARY KEY  (`idPlayer`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;



My Hibernate.cfg.xml looks like this:
Code:
<session-factory>   
   <property name="connection.url">jdbc:mysql://localhost:3306/db060621</property>
   <property name="connection.username">root</property>
   <property name="connection.password">root</property>
   <property name ="connection.driver_class"> com.mysql.jdbc.Driver </property>
   <property name = "dialect" > org.hibernate.dialect.MySQLDialect </property>
   <property name="myeclipse.connection.profile">Golfing</property>
   <mapping resource="is/in/domain/Player.hbm.xml" />
</session-factory>


The Question for listing my users/players is like this:
Code:
private void listUsers() {
      log.info( "####### list user" );
      Transaction tx = session.beginTransaction();
      List players = session.createQuery("from Player").list();
      for (Iterator iter = players.iterator(); iter.hasNext();) {
      Player element = (Player) iter.next();      
      log.info(element);
      }
      tx.commit();
   }


Any suggestions of what I am doing wrong ?
Seeing that this is a syntax error, is it my HQL that is totally wrong.
Did try to write 'select * from player' - that is not working either.
regards, i


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 24, 2006 7:04 pm 
Beginner
Beginner

Joined: Fri Jun 23, 2006 6:40 pm
Posts: 25
Hello

) ENGINE=InnoDB DEFAULT CHARSET=latin1; <----

if mysql work with InnoDB (type of table)
the dialect should be this
org.hibernate.dialect.MySQLInnoDBDialect

about your method

private void listUsers() {
log.info( "####### list user" );
Transaction tx = session.beginTransaction();
List players = session.createQuery("from Player").list();
for (Iterator iter = players.iterator(); iter.hasNext();) {
Player element = (Player) iter.next();
log.info(element);
}
tx.commit();
}
the query is good,
i supposed that you have already initializated the variable session (about of SessionFactory),
try this
Query q = session.createQuery("from Player");
Iterator it=q.list().iterator();

i hope that i can help u, and u can give me and credit :p


Top
 Profile  
 
 Post subject: Didn't fix the prob.
PostPosted: Sun Jun 25, 2006 6:52 am 
Newbie

Joined: Sat Jun 24, 2006 6:26 pm
Posts: 10
Thanks for answering and trying to get me online here, ofcourse you
will have your credit when I pass this obstacle !

I changed my hibernate.cfg.xml to the following:

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="hibernate.connection.driver_class"> org.gjt.mm.mysql.Driver </property>
   <property name="hibernate.connection.password">root</property>
   <property name="hibernate.connection.url"> jdbc:mysql://localhost/db060621</property>
   <property name="hibernate.connection.username"> root</property>
   <!-- property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property -->
   <property name="hibernate.dialect"> org.hibernate.dialect.MySQLInnoDBDialect</property>   
   <!-- JDBC connection pool (use the built-in) -->
   <property name="connection.pool_size">1</property>
   <!-- Enable Hibernate's automatic session context management -->
   <property name="current_session_context_class"> thread</property>
   <!-- Disable the second-level cache -->
   <property name="cache.provider_class"> org.hibernate.cache.NoCacheProvider</property>
   <!-- Echo all executed SQL to stdout -->
   <property name="show_sql"> true</property>
   <!-- Drop and re-create the database schema on startup -->
   <!--  property name="hbm2ddl.auto">create</property  -->

   <mapping resource="is/in/domain/Player.hbm.xml" />
</session-factory>
</hibernate-configuration>


Am i using the wrong jar from mysql ?

The error I get is the following ( probably not a good idea to write the a part of the log here ? ).

Quote:

12:32:24,109 INFO Environment:464 - Hibernate 3.0.5
12:32:24,156 INFO Environment:477 - hibernate.properties not found
12:32:24,187 INFO Environment:510 - using CGLIB reflection optimizer
12:32:24,187 INFO Environment:540 - using JDK 1.4 java.sql.Timestamp handling
12:32:24,343 INFO Configuration:1110 - configuring from resource: /hibernate.cfg.xml
12:32:24,343 INFO Configuration:1081 - Configuration resource: /hibernate.cfg.xml
12:32:25,078 INFO Configuration:444 - Mapping resource: is/in/domain/Player.hbm.xml
12:32:25,328 INFO HbmBinder:260 - Mapping class: is.ingimar.domain.Player -> player
12:32:25,359 INFO Configuration:1222 - Configured SessionFactory: null
12:32:25,375 INFO Configuration:875 - processing extends queue
12:32:25,375 INFO Configuration:879 - processing collection mappings
12:32:25,375 INFO Configuration:888 - processing association property references
12:32:25,375 INFO Configuration:917 - processing foreign key constraints
12:32:25,640 INFO DriverManagerConnectionProvider:41 - Using Hibernate built-in connection pool (not for production use!)
12:32:25,640 INFO DriverManagerConnectionProvider:42 - Hibernate connection pool size: 1
12:32:25,640 INFO DriverManagerConnectionProvider:45 - autocommit mode: false
12:32:25,671 INFO DriverManagerConnectionProvider:80 - using driver: org.gjt.mm.mysql.Driver at URL: jdbc:mysql://localhost/db060621
12:32:25,671 INFO DriverManagerConnectionProvider:86 - connection properties: {user=root, password=****}
12:32:26,625 INFO SettingsFactory:77 - RDBMS: MySQL, version: 5.0.22-community-nt
12:32:26,625 INFO SettingsFactory:78 - JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-3.1.13 ( $Date: 2005-11-17 15:53:48 +0100 (Thu, 17 Nov 2005) $, $Revision$ )
12:32:26,687 INFO Dialect:92 - Using dialect: org.hibernate.dialect.MySQLInnoDBDialect
12:32:26,687 INFO TransactionFactoryFactory:31 - Using default transaction strategy (direct JDBC transactions)
12:32:26,703 INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
12:32:26,703 INFO SettingsFactory:125 - Automatic flush during beforeCompletion(): disabled
12:32:26,703 INFO SettingsFactory:129 - Automatic session close at end of transaction: disabled
12:32:26,703 INFO SettingsFactory:136 - JDBC batch size: 15
12:32:26,703 INFO SettingsFactory:139 - JDBC batch updates for versioned data: disabled
12:32:26,703 INFO SettingsFactory:144 - Scrollable result sets: enabled
12:32:26,703 INFO SettingsFactory:152 - JDBC3 getGeneratedKeys(): enabled
12:32:26,718 INFO SettingsFactory:160 - Connection release mode: null
12:32:26,718 INFO SettingsFactory:184 - Maximum outer join fetch depth: 2
12:32:26,718 INFO SettingsFactory:187 - Default batch fetch size: 1
12:32:26,718 INFO SettingsFactory:191 - Generate SQL with comments: disabled
12:32:26,718 INFO SettingsFactory:195 - Order SQL updates by primary key: disabled
12:32:26,718 INFO SettingsFactory:334 - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
12:32:26,718 INFO ASTQueryTranslatorFactory:21 - Using ASTQueryTranslatorFactory
12:32:26,718 INFO SettingsFactory:203 - Query language substitutions: {}
12:32:26,734 INFO SettingsFactory:209 - Second-level cache: enabled
12:32:26,734 INFO SettingsFactory:213 - Query cache: disabled
12:32:26,734 INFO SettingsFactory:321 - Cache provider: org.hibernate.cache.NoCacheProvider
12:32:26,734 INFO SettingsFactory:228 - Optimize cache for minimal puts: disabled
12:32:26,734 INFO SettingsFactory:237 - Structured second-level cache entries: disabled
12:32:26,750 INFO SettingsFactory:257 - Echoing all SQL to stdout
12:32:26,750 INFO SettingsFactory:261 - Statistics: disabled
12:32:26,765 INFO SettingsFactory:265 - Deleted entity synthetic identifier rollback: disabled
12:32:26,765 INFO SettingsFactory:279 - Default entity-mode: pojo
12:32:26,984 INFO SessionFactoryImpl:152 - building session factory
12:32:27,625 INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI, no JNDI name configured
12:32:27,625 INFO SessionFactoryImpl:379 - Checking 0 named queries
12:32:27,859 ERROR PARSER:35 - *** ERROR: line 1:6: unexpected token: is
org.hibernate.hql.ast.QuerySyntaxError: unexpected token: is near line 1, column 6 [from is.in.domain.Player]
at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:63)


regards, i


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 25, 2006 1:17 pm 
Beginner
Beginner

Joined: Fri Jun 23, 2006 6:40 pm
Posts: 25
hello

i work with mysql in linux and use this

<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/MyDataBase</property>
no
<property name="hibernate.connection.driver_class"> org.gjt.mm.mysql.Driver </property>
the rest of your configuration is the same how my cfg.xml

and i used to work with this driver "mysql-connector-java-3.1.13-bin.jar"

please copy your "Player.hbm.xml"

and the class
is.in.domain.Player <----- and how u call the SessionFactory (if is this in other class, copy too)

12:32:27,859 ERROR PARSER:35 - *** ERROR: line 1:6: unexpected token: is
org.hibernate.hql.ast.QuerySyntaxError: unexpected token: is near line 1, column 6 [from is.in.domain.Player]
at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:63)
there is some cheat in there :p

and please check o indicate waht is the line 1

good luck


Top
 Profile  
 
 Post subject: my package starts with 'is'
PostPosted: Sun Jun 25, 2006 2:42 pm 
Newbie

Joined: Sat Jun 24, 2006 6:26 pm
Posts: 10
Hello!

Hibernate seems to be protesting that I put my domain objects in the package 'is.in.domain'. how come ?
MyEclipse produces the domain-classes from the table such as 'player', but uses a lower-case.
So there seemt to be something wrong here.

regards, I

ps.
Are you using Eclipse/MyEclipse in linux ?
which distribution?
ds


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 25, 2006 2:57 pm 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
Argh, Well. It doesn't sound too ununderstandable. I think it's like using properties called "date", it's almost always impossible to do.

I'd recommend you to see how your tables and columns are being called. Because you're going to risk to face wider problems than Hibernate's... In fact, try to name a table or a column in a dbms using reserved words, you'll see that it's not so simple to handle.

It's like you were trying to generate Java code specifying an class attribute called int... You could do it during, say, modelling, but the code wouldn't compile with the Java compiler...

Here, you say it's your package which is called this way. I don't know if the Hibernate parser is designed to handle this particular case. Try and use anti-quote `` => http://www.hibernate.org/hib_docs/v3/re ... dentifiers
but I don't know if it will correct your problem...

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 25, 2006 3:54 pm 
Beginner
Beginner

Joined: Fri Jun 23, 2006 6:40 pm
Posts: 25
[quote="inkimar"
Are you using Eclipse/MyEclipse in linux ?
which distribution?
ds[/quote]
Hello

yes i have both but i dont use MyEclipse yet, i use xdoclet to generate the Xclass.hbm.xml
without Eclipse

anyway i have FedoraCore 4 ,Eclipse 3.1.2,MyEclipse 4.1.1, i guess that your all code is in src folder

about Player and player use xdoclet, i dunno if is incorporated with MyEclipse, i dont use plugin like MyEclipse yet (i learn first without help, to remember cleary the syntax , and then i use the plugin :p)

is an own decision of each of us :p

copy your class


Top
 Profile  
 
 Post subject: giving you a credit ?
PostPosted: Mon Jun 26, 2006 7:01 am 
Newbie

Joined: Sat Jun 24, 2006 6:26 pm
Posts: 10
did u receive it, or am I missing something.
Your answer was good enough for my solution, probz with my package-name
starting with 'is'.

regards, i


Top
 Profile  
 
 Post subject: Re: giving you a credit ?
PostPosted: Mon Jun 26, 2006 7:39 am 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
inkimar wrote:
did u receive it, or am I missing something.
Your answer was good enough for my solution, probz with my package-name
starting with 'is'.

regards, i


Who are you talking to ? What did you do to correct your problem ?

If one or more of our answers helped you, please don't forget to rate it :).

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject: Re: giving you a credit ?
PostPosted: Mon Jun 26, 2006 1:26 pm 
Beginner
Beginner

Joined: Fri Jun 23, 2006 6:40 pm
Posts: 25
hello

mmm

so if i won a credit, well i dont recieved yet :p

and what o how did you resolve the problem???


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