Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Setting up Hibernate with MySQL and JBOSS 7 forst time.
PostPosted: Thu Dec 01, 2011 2:22 pm 
Newbie

Joined: Thu Dec 01, 2011 2:00 pm
Posts: 1
Hi,

I have setup my mysql datasource in standalone.xml and deployed the mysql driver. I am looking at a sample app from the jboss getting started site which uses hibernate and an in memory data source.

Here is the persistence.xml from the sample...

Code:
02. <persistence xmlns="http://java.sun.com/xml/ns/persistence"
03.    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
04.    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
05.    version="2.0">
06.    <persistence-unit name="loginDatabase">
07.       <provider>org.hibernate.ejb.HibernatePersistence</provider>
08.       <jta-data-source>java:jboss/datasources/ExampleDS</jta-data-source>
09.       <properties>
10.          <property name="hibernate.hbm2ddl.auto" value="create-drop" />
11.       </properties>
12.    </persistence-unit>
13. </persistence>


I edited it to use my data source...

Code:
02. <persistence xmlns="http://java.sun.com/xml/ns/persistence"
03.    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
04.    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
05.    version="2.0">
06.    <persistence-unit name="myApp">
07.       <provider>org.hibernate.ejb.HibernatePersistence</provider>
08.       <jta-data-source>java:jboss/datasources/MySqlDS</jta-data-source>
09.       <properties>
10.          <property name="hibernate.hbm2ddl.auto" value="create-drop" />
11.       </properties>
12.    </persistence-unit>
13. </persistence>


The sample import.sql file simply has this...

Code:
insert into User (username, name, password) values ('demo', 'Demo User', 'demo')


I changed it to match my table in my database...

Code:
insert into Baselines (id, name) values (0, 'AWD')


First question is where is the the actual DATABASE name??? I don't see a use command anywhere?

Second, I'm getting the following error when I start Jboss/Deploy my app....

Quote:
3:18:58,034 INFO [org.jboss.weld] (MSC service thread 1-1) Processing CDI deployment: coda.war
13:18:58,187 INFO [org.jboss.weld] (MSC service thread 1-2) Starting Services for CDI deployment: coda.war
13:18:58,217 INFO [org.jboss.weld.Version] (MSC service thread 1-2) WELD-000900 1.1.2 (Final)
13:18:58,235 INFO [org.jboss.jpa] (MSC service thread 1-3) starting Persistence Unit Service 'coda.war#Coda'
13:18:58,316 INFO [org.hibernate.annotations.common.Version] (MSC service thread 1-3) HCANN000001: Hibernate Commons Annotations {4.0.0.CR2}
13:18:58,320 INFO [org.hibernate.Version] (MSC service thread 1-3) HHH00412:Hibernate Core {4.0.0.CR2}
13:18:58,321 INFO [org.hibernate.cfg.Environment] (MSC service thread 1-3) HHH00206:hibernate.properties not found
13:18:58,322 INFO [org.hibernate.cfg.Environment] (MSC service thread 1-3) HHH00021:Bytecode provider name : javassist
13:18:58,334 INFO [org.hibernate.ejb.Ejb3Configuration] (MSC service thread 1-3) HHH00204:Processing PersistenceUnitInfo [
name: Coda
...]
13:18:58,400 INFO [org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator] (MSC service thread 1-3) HHH00130:Instantiating explicit connection provider: org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider
13:18:58,432 INFO [org.hibernate.dialect.Dialect] (MSC service thread 1-3) HHH00400:Using dialect: org.hibernate.dialect.MySQLDialect
13:18:58,444 INFO [org.hibernate.engine.transaction.internal.TransactionFactoryInitiator] (MSC service thread 1-3) HHH00268:Transaction strategy: org.hibernate.engine.transaction.internal.jta.CMTTransactionFactory
13:18:58,446 INFO [org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory] (MSC service thread 1-3) HHH00397:Using ASTQueryTranslatorFactory
13:18:58,543 INFO [org.hibernate.tool.hbm2ddl.SchemaExport] (MSC service thread 1-3) HHH00227:Running hbm2ddl schema export
13:18:58,556 ERROR [org.hibernate.tool.hbm2ddl.SchemaExport] (MSC service thread 1-3) HHH00231:Schema export unsuccessful: org.hibernate.tool.hbm2ddl.ImportScriptException: Error during import script execution at line 2
at org.hibernate.tool.hbm2ddl.SchemaExport.importScript(SchemaExport.java:443) [hibernate-core-4.0.0.CR2.jar:4.0.0.CR2]
at org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:365) [hibernate-core-4.0.0.CR2.jar:4.0.0.CR2]
at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:291) [hibernate-core-4.0.0.CR2.jar:4.0.0.CR2]
at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:280) [hibernate-core-4.0.0.CR2.jar:4.0.0.CR2]
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:440) [hibernate-core-4.0.0.CR2.jar:4.0.0.CR2]
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1722) [hibernate-core-4.0.0.CR2.jar:4.0.0.CR2]
at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:76) [hibernate-entitymanager-4.0.0.CR2.jar:4.0.0.CR2]
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:899) [hibernate-entitymanager-4.0.0.CR2.jar:4.0.0.CR2]
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:884) [hibernate-entitymanager-4.0.0.CR2.jar:4.0.0.CR2]
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:73) [hibernate-entitymanager-4.0.0.CR2.jar:4.0.0.CR2]
at org.jboss.as.jpa.service.PersistenceUnitService.createContainerEntityManagerFactory(PersistenceUnitService.java:143) [jboss-as-jpa-7.0.2.Final.jar:7.0.2.Final]
at org.jboss.as.jpa.service.PersistenceUnitService.start(PersistenceUnitService.java:77) [jboss-as-jpa-7.0.2.Final.jar:7.0.2.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1824)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1759)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) [:1.6.0_20]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) [:1.6.0_20]
at java.lang.Thread.run(Thread.java:636) [:1.6.0_20]
Caused by: java.sql.SQLException: No database selected
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3609)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3541)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2002)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2163)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2618)
at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1749)
at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1666)
at org.jboss.jca.adapters.jdbc.WrappedStatement.executeUpdate(WrappedStatement.java:349)
at org.hibernate.tool.hbm2ddl.DatabaseExporter.export(DatabaseExporter.java:64) [hibernate-core-4.0.0.CR2.jar:4.0.0.CR2]
at org.hibernate.tool.hbm2ddl.SchemaExport.importScript(SchemaExport.java:438) [hibernate-core-4.0.0.CR2.jar:4.0.0.CR2]
... 16 more

13:18:58,559 INFO [org.hibernate.tool.hbm2ddl.SchemaExport] (MSC service thread 1-3) HHH00230:Schema export complete
13:18:58,577 INFO [org.jboss.weld] (MSC service thread 1-4) Starting weld service
13:18:58,952 INFO [javax.enterprise.resource.webcontainer.jsf.config] (MSC service thread 1-2) Initializing Mojarra 2.1.3 (SNAPSHOT 20110825) for context '/coda'
13:18:59,656 INFO [org.hibernate.validator.util.Version] (MSC service thread 1-2) Hibernate Validator 4.2.0.Final
13:18:59,878 INFO [org.jboss.web] (MSC service thread 1-2) registering web context: /coda
13:18:59,879 INFO [org.jboss.as] (MSC service thread 1-4) JBoss AS 7.0.2.Final "Arc" started in 5076ms - Started 158 of 217 services (59 services are passive or on-demand)
13:19:00,010 INFO [org.jboss.as.server.controller] (DeploymentScanner-threads - 2) Deployed "coda.war"


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

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.