The Spring project (in its production form) will be using a MySQL database. I want the tests ran on the project to use HYPERSONIC_IN_MEMORY.
I've added the following new files in the test/resources folder.
database.properties
applicationContext.xml
test-persistence.xml
However, the project throws a MYSQL syntax error (it's trying to use MySQL with HYPERSONIC somehow).
Considering the fact that I'm a total beginner (first project in Spring), I'd like to know what the steps are to switching databases for testing (what I might be doing wrong).
LE:
This is what I'm getting when running maven tests:
Tests run: 9, Failures: 0, Errors: 9, Skipped: 0, Time elapsed: 12.29 sec <<< FAILURE!
testCountAllAccountAllocations(com.mms.pone.portal.domain.AccountAllocationIntegrationTest) Time elapsed: 11.813 sec <<< ERROR!
org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Cannot open connection
at org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:427)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:371)
at org.springframework.test.context.transaction.TransactionalTestExecutionListener$TransactionContext.startTransaction(TransactionalTestExecutionListener.java:513)
at org.springframework.test.context.transaction.TransactionalTestExecutionListener.startNewTransaction(TransactionalTestExecutionListener.java:271)
at org.springframework.test.context.transaction.TransactionalTestExecutionListener.beforeTestMethod(TransactionalTestExecutionListener.java:164)
at org.springframework.test.context.TestContextManager.beforeTestMethod(TestContextManager.java:358)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:73)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:172)
at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:104)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:70)
Caused by: javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Cannot open connection
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1387)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1315)
at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:1397)
at org.hibernate.ejb.TransactionImpl.begin(TransactionImpl.java:63)
at org.springframework.orm.jpa.DefaultJpaDialect.beginTransaction(DefaultJpaDialect.java:70)
at org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:377)
... 31 more
Caused by: org.hibernate.exception.GenericJDBCException: Cannot open connection
And a lot more of those. I get the feeling that maven isn't using the new xml files and still sticking to the old ones.
Any way I can figure that out?
Search for org.hibernate.dialect.MySQLDialect and replace it with org.hibernate.dialect.HSQLDialect (docs)
[EDIT] The error says "Cannot open connection". Check the JDBC URL, user+password and for more errors further up in the output.
I'm assuming this is how your original applicationContext.xml looked (also assuming that the persistence.xml file defines a persitence unit with jndi name 'testEM')
<jee:jndi-lookup id="entityManagerFactory" jndi-name="java:comp/env/testEM" />
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
For testing purposes, you basically need to override how entityManagerFactory is created.
In your applicationContext-test.xml file override 'entityManagerFactory' bean definition as shown in the snippet below. Create a 'META-INF/test-persistence.xml' in src/test/resources that creates a connection to hsql in-memory db.
test-persistence.xml
<persistence-unit name="testPu">
<properties>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.connection.password" value=""/>
<property name="hibernate.connection.url" value="jdbc:hsqldb:mem:schemaname"/>
<property name="hibernate.connection.username" value="sa"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
</properties>
</persistence-unit>
applicationContext-test.xml
<!-- Import the original applicationContext and override properties for test purposes -->
<import resource="classpath:applicationContext" />
<!-- In our case, we need to override entityManagerFactory definition -->
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceXmlLocation" value="classpath*:META-INF/test-persistence.xml" />
<!-- other properties (omitted) -->
</bean>
Related
I am using Spring Batch and connecting to Oracle 12c instance.
org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: ORA-28040: No matching authentication protocol
And I am getting the below error :
org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: ORA-28040: No matching authentication protocol
at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:80)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:619)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:684)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:716)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:726)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:781)
at org.springframework.batch.core.repository.dao.JdbcJobInstanceDao.getJobInstance(JdbcJobInstanceDao.java:145)
at org.springframework.batch.core.repository.support.SimpleJobRepository.getLastJobExecution(SimpleJobRepository.java:284)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:280)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
at com.sun.proxy.$Proxy1.getLastJobExecution(Unknown Source)
at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:98)
at CustomerFileGenerationMain.main(CustomerFileGenerationMain.java:28)
Caused by: java.sql.SQLException: ORA-28040: No matching authentication protocol
Spring Batch xml file
<bean id="DataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
<property name="username" value="MY_OWNER"/>
<property name="url" value="jdbc:oracle:thin:#//localhost:1527/myCloud" />
<property name="password" value="" />
</bean>
<bean id="transactionManager" class="org.springframework.batch.support.transaction.ResourcelessTransactionManager" />
<bean id="jobRepository" class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean" >
<property name="dataSource" ref="DataSource" />
<property name="transactionManager" ref="transactionManager" />
<property name="databaseType" value="ORACLE" />
</bean>
and pom.xml file -
Only this dependency I used
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.3</version>
</dependency>
I tried below as well..
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc7</artifactId>
<version>12.1.0.1</version>
</dependency>
Please guide how to convert below code to XML bean ?
#Bean(name = "DataSource")
public DataSource batchDataSource() throws IOException {
OracleDataSource ds = null;
MCUserInfoFactory userInfoFactory = new MCUserInfoFactory();
try {
MCUserInfo userInfo = userInfoFactory.getMCUserInfo(XXXXLabel);
if (userInfo != null) {
ds = getDataSource(userInfo, edsurl);
}
} catch (Exception e) {
}
return ds;
}
I am using the following version -
/:/oracle/home $ sqlplus / as sysdba
-bash: sqlplus: command not found
/:/oracle/home $ . ~/.profile
/:/oracle/home $ sqlplus / as sysdba
SQL*Plus: Release 12.1.0.2.0 Production on Thu Jun 28 01:56:56 2018
Copyright (c) 1982, 2014, Oracle. All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Advanced Analytics
and Real Application Testing options
Check driver file(.jar) version and ORACLE db version you are using is compatible with each other,
usually that causes this issue.
I am trying to create a simple project with Java EE. However, I get a huge stacktrace.
org.apache.openejb.config.ValidationFailedException: Module failed validation. AppModule(name=BarSystem_war_exploded)
at org.apache.openejb.config.ReportValidationResults.deploy(ReportValidationResults.java:88)
at org.apache.openejb.config.AppInfoBuilder.build(AppInfoBuilder.java:312)
at org.apache.openejb.config.ConfigurationFactory.configureApplication(ConfigurationFactory.java:974)
at org.apache.tomee.catalina.TomcatWebAppBuilder.startInternal(TomcatWebAppBuilder.java:1227)
at org.apache.tomee.catalina.TomcatWebAppBuilder.configureStart(TomcatWebAppBuilder.java:1100)
at org.apache.tomee.catalina.GlobalListenerSupport.lifecycleEvent(GlobalListenerSupport.java:130)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5416)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652)
at org.apache.tomee.catalina.TomcatWebAppBuilder.deployWar(TomcatWebAppBuilder.java:663)
at org.apache.tomee.catalina.TomcatWebAppBuilder.deployWebApps(TomcatWebAppBuilder.java:622)
at org.apache.tomee.catalina.deployment.TomcatWebappDeployer.deploy(TomcatWebappDeployer.java:43)
at org.apache.openejb.assembler.DeployerEjb.deploy(DeployerEjb.java:176)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:192)
at org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:173)
at org.apache.openejb.security.internal.InternalSecurityInterceptor.invoke(InternalSecurityInterceptor.java:35)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:192)
at org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:173)
at org.apache.openejb.monitoring.StatsInterceptor.record(StatsInterceptor.java:181)
at org.apache.openejb.monitoring.StatsInterceptor.invoke(StatsInterceptor.java:100)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:192)
at org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:173)
at org.apache.openejb.core.interceptor.InterceptorStack.invoke(InterceptorStack.java:85)
at org.apache.openejb.core.stateless.StatelessContainer._invoke(StatelessContainer.java:227)
at org.apache.openejb.core.stateless.StatelessContainer.invoke(StatelessContainer.java:194)
at org.apache.openejb.server.ejbd.EjbRequestHandler.doEjbObject_BUSINESS_METHOD(EjbRequestHandler.java:370)
at org.apache.openejb.server.ejbd.EjbRequestHandler.processRequest(EjbRequestHandler.java:181)
So I have a UserDAO like this:
#Stateless
public class UserDAO {
#PersistenceContext
private EntityManager em;
public void createUser(String name) {
// User user = new User();
// user.setName(name);
// em.persist(user);
// System.out.println("Maliiii");
}
}
when I comment the EntityManager and #PersistenceContext, the TomEE runs without exceptions. However only by removing comments and deploying, I get a huge stacktrace. Before I switch to TomEE, I tried with glassfish and this problem did not occure. However, there was a problem setting up the jdbc connection pool in the application manager, so that's why i switched to tomee.
persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence-unit name="NewPersistenceUnit">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/bar"/>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.connection.username" value="root"/>
<property name="hibernate.connection.password" value="root"/>
<!--<property name="hibernate.archive.autodetection" value="class"/>-->
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true"/>
<property name="hbm2ddl.auto" value="create"/>
</properties>
</persistence-unit>
any ideas how to solve it?
First thing that comes to mind is that standard installation of TomEE has OpenJPA implementation of JPA, not hibernate is as the case with . If this is the case, try to remove <provider> from persistence.xml. There is a version of TomEE with Eclipselink (called Plume), but no official version with hibernate. If you want hibernate, you may include it as a dependency within you WAR.
However, glassfish also does not include hibernate, so you probably already have hibernate in your WAR?
As #OndrejM said tomcat uses apache open jpa as it's JPA Implementation so you can change your provider to
org.apache.openjpa.persistence.PersistenceProviderImpl
to specify the persistence provider implementation
Also you will need to change the JDBC configuration propertie names to use OpneJpa instead of hibernate to be like
**
<property name="openjpa.ConnectionDriverName"value="your value" />
<property name="openjpa.ConnectionURL" value="your value" />
<property name="openjpa.ConnectionUserName" value="your value" />
<property name="openjpa.ConnectionPassword" value="your value" />
**
in case you need to work with hibernate , you may view this question
How to use TomEE with Hibernate
So I found out the error, and it really was a stupid one.
Since I am using InteliJ, I am querying the "users" table from the ide. I also did query it from mysql, but without noticing the changes. It turned out that the jpa created a "Users" and "USERS" table (I tried changing the name in the #Entity) and all the time it was writing to these two tables. So I noticed the tables after refreshing the "Tables" in MySql workbench. Thanks to all for the help, and I am sorry for the dumb problem :)
I have inherited a maven based project that was created with Netbeans 7.4. I have configured a local Glassfish 3.1.2.2 in the servers tab, set up JDBC connection pools and resources and can debug the project correctly.
However, I created 2 more tables in one of the connected databases, and let Netbeans generate 2 new entities from the Database schema. The entities are generated correctly, but when I start using them and start a debug session on the glassfish server I can see error messages being logged saying that the entities are not declared in the persistence unit.
I am trying to find what persistence.xml is being used, but although I find a lot of old ones inside the project structure (that I didn't create myself and I don't have contact with the authors) I cannot find any that seems to be the one being used. Hibernate only refers to the Persistence Unit name, not to the path of the file being used.
I am new to Java Persistence, so I am a bit confused. Can anybody suggest how I find, or recreate, the persistence.xml file?
EDIT: Here is the stack trace:
INFO: HHH000412: Hibernate Core {4.2.6.Final}
INFO: HHH000206: hibernate.properties not found
INFO: HHH000021: Bytecode provider name : javassist
INFO: HHH000204: Processing PersistenceUnitInfo [
name: core_rw_pu_hibernate
...]
INFO: HHH000130: Instantiating explicit connection provider: org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
SEVERE: Exception while invoking class org.glassfish.persistence.jpa.JPADeployer prepare method
SEVERE: Exception while preparing the app
SEVERE: [PersistenceUnit: core_rw_pu_hibernate] Unable to build EntityManagerFactory
javax.persistence.PersistenceException: [PersistenceUnit: core_rw_pu_hibernate] Unable to build EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:924)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:899)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:76)
at org.glassfish.persistence.jpa.PersistenceUnitLoader.loadPU(PersistenceUnitLoader.java:206)
at org.glassfish.persistence.jpa.PersistenceUnitLoader.<init>(PersistenceUnitLoader.java:120)
at org.glassfish.persistence.jpa.JPADeployer$1.visitPUD(JPADeployer.java:224)
at org.glassfish.persistence.jpa.JPADeployer$PersistenceUnitDescriptorIterator.iteratePUDs(JPADeployer.java:495)
at org.glassfish.persistence.jpa.JPADeployer.createEMFs(JPADeployer.java:233)
at org.glassfish.persistence.jpa.JPADeployer.prepare(JPADeployer.java:168)
at com.sun.enterprise.v3.server.ApplicationLifecycle.prepareModule(ApplicationLifecycle.java:871)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:410)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:240)
at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:389)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:348)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:363)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1085)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1200(CommandRunnerImpl.java:95)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1291)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1259)
at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:461)
at com.sun.enterprise.v3.admin.AdminAdapter.service(AdminAdapter.java:212)
at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:179)
at com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:117)
at com.sun.enterprise.v3.services.impl.ContainerMapper$Hk2DispatcherCallable.call(ContainerMapper.java:354)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:744)
Caused by: org.hibernate.AnnotationException: Use of #OneToMany or #ManyToMany targeting an unmapped class: com.acme.ee.domain.entity.DeviceEntity.deviceInOuts[com.acme.ee.domain.entity.DeviceInOuts]
at org.hibernate.cfg.annotations.CollectionBinder.bindManyToManySecondPass(CollectionBinder.java:1059)
at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:733)
at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:668)
at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:69)
at org.hibernate.cfg.Configuration.originalSecondPassCompile(Configuration.java:1632)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1390)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1777)
at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:96)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:914)
... 38 more
In a normal maven-based web application project the persistence.xml has to be placed in the folder:
src/main/resources/META-INF
In the NetBeans Projects tab this folder can be seen by opening "Other Sources" (should be right under "Source Packages").
If this isn't the right file, you have the option to search for the name of the PersistenceUnit in the whole project. The name has to be declared in the persistence.xml. If it finds multiple files you can find the one which is actually used by making the files unparsable one by one. To do this, just remove a closing tag (like </provider>) in the first file, save it and deploy it. If it throws an error which tells you the file is unparsable (probably something containing the class SAXParser), this is the file which is used. If it doesn't throw an error, try again with the next file.
To fix the initial problem (new entities not in persistence unit) make sure you add the new entity classes in the persistence.xml like this:
<class>com.company.SomeClass</class>
Another option is to add the following to your persistence.xml:
<exclude-unlisted-classes>false</exclude-unlisted-classes>
This should automatically discover all entities, but sometimes this doesn't work because the project structure doesn't fit, then you have to explicitly list every entity.
your persistence.xml should have information about your connection to the database like bellow:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="YOUR_PERSISTENCE_UNIT_NAME" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>jdbc/YOUR_JNDI_NAME</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<!--<property name="javax.persistence.schema-generation.database.action" value="none"/> -->
<property name="hibernate.archive.autodetection" value="class"/>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.SunOneJtaPlatform"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/YOUR_SCHEMA_NAME?zeroDateTimeBehavior=convertToNull"/>
<property name="hibernate.connection.username" value="YOUR_USERNAME"/>
<property name="hibernate.connection.password" value="YOUR_PASSWORD"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.hbm2ddl.auto" value="update" />
</properties>
</persistence-unit>
</persistence>
I'm trying to get some code I was passed up and running. It appears to use the Hibernate framework. I've gotten past most of the errors tweaking the configuration, but this one has me dead stumped.
It's trying to connect to two databases: gameapp and gamelog. Both exist. It seems to have issues connecting to gamelog, but none connecting to gameapp (later in the init, it connects to and loads other DBs just fine). Below, I've pasted the error and exception stack dump.
I imaging there's something else in the configs, so I've also included the configuration file for that db. I know this is very vague, but I'm hoping some pro can see the stupid mistake I'm missing.
<?xml version="1.0" encoding="GBK"?>
<!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="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://127.0.0.1:3306/gamelog</property>
<property name="connection.username">root</property>
<property name="connection.password"></property>
<property name="connection.useUnicode">true</property>
<property name="connection.characterEncoding">UTF-8</property>
<property name="hibernate.jdbc.batch_size">100</property>
<property name="jdbc.fetch_size">1</property>
<property name="hbm2ddl.auto">none</property><!-- update -->
<property name="connection.useUnicode">true</property>
<property name="show_sql">true</property>
<!-- c3p0-configuration -->
<property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">10</property>
<property name="hibernate.c3p0.timeout">30</property>
<property name="hibernate.c3p0.idle_test_period">30</property>
<property name="hibernate.c3p0.max_statements">0</property>
<property name="hibernate.c3p0.acquire_increment">5</property>
</session-factory>
</hibernate-configuration>
Exception and stack trace:
2010-04-30 17:50:00,411 WARN [org.hibernate.cfg.SettingsFactory] - Could not obtain connection metadata
java.sql.SQLException: An attempt by a client to checkout a Connection has timed out.
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:106)
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:65)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:527)
at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:128)
at org.hibernate.connection.C3P0ConnectionProvider.getConnection(C3P0ConnectionProvider.java:35)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:76)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1933)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1216)
at com.database.hibernate.util.HibernateFactory.<init>(Unknown Source)
at com.database.hibernate.util.HibernateUtil.<clinit>(Unknown Source)
at com.server.databaseop.goodOp.GoodOpImpl.initBreedGoods(Unknown Source)
at com.server.databaseop.goodOp.GoodOpImpl.access$000(Unknown Source)
at com.server.databaseop.goodOp.GoodOpImpl$1.run(Unknown Source)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:351)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:178)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:165)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:267)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:636)
Caused by: com.mchange.v2.resourcepool.TimeoutException: A client timed out while waiting to acquire a resource from com.mchange.v2.resourcepool.BasicResourcePool#ca470 -- timeout at awaitAvailable()
at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1317)
at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:557)
at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:477)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:525)
... 18 more
If you have set C3P0's "checkoutTimeout" property to something other than 0 you might be timing out too quickly (that was my problem, solution: bumped it to 2000 milliseconds from 500).
Alternatively, there's a workaround for this warning:
Set the hibernate.temp.use_jdbc_metadata_defaults property to false.
Found this in http://www.docjar.com/html/api/org/hibernate/cfg/SettingsFactory.java.html, though there may be side effects of not having Hibernate extract JDBC Metadata defaults.
Actually that's not even an authentication error. Is MySQL even running or bound to localhost?
does telnet 127.0.0.1 3306 work?
if so, install the mysql client on the box and try
mysql --user=root --ip=127.0.0.1
and see what happens
Check if you can connect to the gamelog mysql database on the command line with the root user and no password (!). As a side note, I'd recommend to set a password for root and to use a different account to connect to the database from your application, but that's another story.
I have been recently running into an issue in which my web application will not start properly and the stack trace doesn't indicate exactly what happened. I have been able to isolate it to an event listener that I wrote. Whenever I attempt to activate it, I get a very generic exception:
org.jboss.seam.InstantiationException: Could not instantiate Seam component: entityManagerFactory
at org.jboss.seam.Component.newInstance(Component.java:2144)
at org.jboss.seam.contexts.Contexts.startup(Contexts.java:304)
at org.jboss.seam.contexts.Contexts.startup(Contexts.java:278)
at org.jboss.seam.contexts.ServletLifecycle.endInitialization(ServletLifecycle.java:116)
at org.jboss.seam.init.Initialization.init(Initialization.java:740)
at org.jboss.seam.servlet.SeamListener.contextInitialized(SeamListener.java:36)
at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:645)
at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:189)
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:978)
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:586)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:349)
at org.mortbay.jetty.plugin.JettyWebAppContext.doStart(JettyWebAppContext.java:102)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55)
at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:165)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:162)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55)
at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:165)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55)
at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:92)
at org.eclipse.jetty.server.Server.doStart(Server.java:228)
at org.mortbay.jetty.plugin.JettyServer.doStart(JettyServer.java:69)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55)
at org.mortbay.jetty.plugin.AbstractJettyMojo.startJetty(AbstractJettyMojo.java:433)
at org.mortbay.jetty.plugin.AbstractJettyMojo.execute(AbstractJettyMojo.java:377)
at org.mortbay.jetty.plugin.JettyRunWarMojo.execute(JettyRunWarMojo.java:68)
at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:569)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:539)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Now, I had this problem in the past, and that was caused by me trying to over optimize each entity class by making the setters and getters final. Hibernate needs to setup proxying for the entity classes so it can lazy load stuff, so if I make a setter/getter final, it can't do that.
The event listener I want to use essentially listens for persist and update events. When one happens, it is supposed to set the current date on a field annotated with the corresponding annotation to mark the field as requiring a current date to be set.
I am thinking that this is because I am running a newer version of javassist:
javassist:javassist:jar:3.11.0.GA:runtime
Has anyone run into this issue before?
I am running JBoss Seam 2.2.0.GA on Jetty 7.
persistence.xml (abbreviated version)
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0">
<persistence-unit name="${jdbc.database}" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<non-jta-data-source>${jdbc.datasource.name}</non-jta-data-source>
<class> ... classes go here </class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="hibernate.dialect" value="${hibernate.dialect}"/>
<property name="hibernate.hbm2ddl.auto" value="${ddl.mode}"/>
<property name="hibernate.show_sql" value="${hibernate.showSql}"/>
<property name="format_sql" value="${hibernate.formatSql}"/>
<property name="use_sql_comments" value="${hibernate.useSqlComments}"/>
<property name="hibernate.jdbc.batch_versioned_data" value="true"/>
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.EHCacheProvider"/>
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.EhCacheProvider"/>
<property name="hibernate.cache.use_query_cache" value="true"/>
<property name="hibernate.cache.provider_configuration_file_resource_path" value="/ehcache.xml"/>
<property name="hibernate.connection.release_mode" value="after_transaction"/>
<property name="hibernate.connection.autocommit" value="true"/>
<!-- Current Date listeners -->
<!--
<property name="hibernate.ejb.event.pre-insert" value="org.hibernate.ejb.event.EJB3PersistEventListener,com.walterjwhite.listener.persistence.listener.SetCurrentDateListener"/>
<property name="hibernate.ejb.event.pre-update" value="org.hibernate.ejb.event.EJB3MergeEventListener,com.walterjwhite.listener.persistence.listener.SetCurrentDateListener"/>
-->
<!-- Envers listeners -->
<property name="hibernate.ejb.event.post-insert" value="org.hibernate.ejb.event.EJB3PostInsertEventListener,org.hibernate.envers.event.AuditEventListener"/>
<property name="hibernate.ejb.event.post-update" value="org.hibernate.ejb.event.EJB3PostUpdateEventListener,org.hibernate.envers.event.AuditEventListener"/>
<property name="hibernate.ejb.event.post-delete" value="org.hibernate.ejb.event.EJB3PostDeleteEventListener,org.hibernate.envers.event.AuditEventListener"/>
<property name="hibernate.ejb.event.pre-collection-update" value="org.hibernate.envers.event.AuditEventListener"/>
<property name="hibernate.ejb.event.pre-collection-remove" value="org.hibernate.envers.event.AuditEventListener"/>
<property name="hibernate.ejb.event.post-collection-recreate" value="org.hibernate.envers.event.AuditEventListener"/>
<!-- Hibernate Search -->
<property name="hibernate.search.default.directory_provider" value="org.hibernate.search.store.FSDirectoryProvider"/>
<property name="hibernate.search.default.indexBase" value="${application.directory}/lucene/indexes"/>
</properties>
</persistence-unit>
</persistence>
When I use Javassist 3.4.GA instead of 3.11.GA, I get this error.
java.lang.IllegalAccessError: tried to access class javassist.bytecode.StackMapTable$Writer from class org.jboss.seam.util.ProxyFactory
at org.jboss.seam.util.ProxyFactory.makeConstructor(ProxyFactory.java:803)
at org.jboss.seam.util.ProxyFactory.makeConstructors(ProxyFactory.java:685)
at org.jboss.seam.util.ProxyFactory.make(ProxyFactory.java:565)
at org.jboss.seam.util.ProxyFactory.createClass3(ProxyFactory.java:346)
at org.jboss.seam.util.ProxyFactory.createClass2(ProxyFactory.java:325)
at org.jboss.seam.util.ProxyFactory.createClass(ProxyFactory.java:284)
at org.jboss.seam.Component.createProxyFactory(Component.java:2426)
at org.jboss.seam.Component.getProxyFactory(Component.java:1513)
at org.jboss.seam.Component.wrap(Component.java:1504)
at org.jboss.seam.Component.instantiateJavaBean(Component.java:1442)
at org.jboss.seam.Component.instantiate(Component.java:1359)
at org.jboss.seam.Component.newInstance(Component.java:2122)
at org.jboss.seam.contexts.Contexts.startup(Contexts.java:304)
at org.jboss.seam.contexts.Contexts.startup(Contexts.java:278)
at org.jboss.seam.contexts.ServletLifecycle.endInitialization(ServletLifecycle.java:116)
at org.jboss.seam.init.Initialization.init(Initialization.java:740)
at org.jboss.seam.servlet.SeamListener.contextInitialized(SeamListener.java:36)
at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:645)
at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:189)
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:978)
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:586)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:349)
at org.mortbay.jetty.plugin.JettyWebAppContext.doStart(JettyWebAppContext.java:102)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55)
at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:165)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:162)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55)
at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:165)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55)
at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:92)
at org.eclipse.jetty.server.Server.doStart(Server.java:228)
at org.mortbay.jetty.plugin.JettyServer.doStart(JettyServer.java:69)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55)
at org.mortbay.jetty.plugin.AbstractJettyMojo.startJetty(AbstractJettyMojo.java:433)
at org.mortbay.jetty.plugin.AbstractJettyMojo.execute(AbstractJettyMojo.java:377)
at org.mortbay.jetty.plugin.JettyRunWarMojo.execute(JettyRunWarMojo.java:68)
at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:569)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:539)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Walter
My advice is:
Always generate your project by using Seam-gen
This way, you do not have to worry about libraries that your project needs.
Message is:
org.jboss.seam.InstantiationException: Could not instantiate Seam component: entityManagerFactory
Have you set up your EntityManagerFactory ?
If not, do as follows (I suppose you are not using JTA environment. So i will show you a RESOURCE_LOCAL EntityManagerFactory)
/WEB-INF/components.xml
<!--I AM USING 2.1 version-->
<!--SO I SUPPOSE YOU HAVE TO REPLACE 2.1 by 2.2-->
<components xmlns="http://jboss.com/products/seam/components"
xmlns:core="http://jboss.com/products/seam/core"
xmlns:persistence="http://jboss.com/products/seam/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.1.xsd
http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.1.xsd
http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.1.xsd">
<!--SET UP A MANAGED EntityManagerFactory-->
<!--DEFAULT TO ScopeType.APPLICATION-->
<persistence:entity-manager-factory name="entityManagerFactory" persistence-unit-name="<PERSISTENCE_UNIT_NAME_MUST_MATCH_NAME_ATTRIBUTE_IN_PERSISTENCE.XML>"/>
<!--SET UP A MANAGED EntityManager-->
<!--DEFAULT TO ScopeType.CONVERSATION-->
<persistence:managed-persistence-context name="entityManager" entity-manager-factory="#{entityManagerFactory}" auto-create="true"/>
<!--SET UP SEAM TRANSACTION MANAGER-->
<!--IT TAKES CARE OF CALLING BEGIN AND COMMIT-->
<tx:entity-transaction entity-manager="#{entityManager}"/>
</components>
Notice when using auto-create attribute equal true, you do not have to set up create attribute in #In annotation
// You do not need to set up create attribute
// because of auto-create atrribute in persistence:managed-persistence-context component
#In(create=true)
private EntityManager entityManager;
Takes care by using naming convention, EntityManager reference must match name attribute in persistence:managed-persistence-context component.
Now you have to define your /META-INF/persistence.xml
/META-INF/persistence.xml
<persistence-unit name="<PERSISTENCE_UNIT_NAME_GOES_HERE>" transaction-type="RESOURCE_LOCAL">
// Set up properties here
</persistence-unit>
If you are using a data source that can be obtained by JNDI - you need to set up according your target application server (TOMCAT, JETTY etc), do as follows
/META-INF/persistence.xml
<persistence-unit name="<PERSISTENCE_UNIT_NAME_GOES_HERE>">
<non-jta-data-source>jdbc/myAppDS</non-jta-data-source>
</persistence-unit>
And if you want to set up a current date, do as follows instead of using Hibernate event
<!--currentDate IS A BUILT-IN Seam component-->
<!--DEFAULT TO ScopeType.STATELESS-->
<!--ScopeType.STATELESS IS SIMILAR TO Spring prototype scope-->
<h:inputHidden value="#{currentDate}" rendered="false" binding="#{myBackingBean.currentDate}"/>
About final keyword, maybe you want to see I get a log message: reflection optimizer disabled
regards,
Well, I didn't really get any good answers. In this particular instance that I had the problem, the problem was having an incorrect version of my dependencies configured. That is one of the negatives with having my projects split up as much as they are. I have to pay close attention to which version I'm using in each project.
In other cases, it seemed to me that I had issues with a Lucene configuration. In either case, I would prefer to see the stack trace so I can look at it and then, oops, I have a bad jar or something like that.
Walter