[Beginners Corner] - Connecting to Hibernate
by revof11
All,
I have been working on a very simple EJB 3 sample setup for myself and am working on the persistence setup for testing simple data storage via an EntityManager. The problem is that I am unable to connect to the internal HSQL database using my configurations. I would appreciate if someone could help me out.
The following are the steps I took to attempt this database setup:
1. Install JBoss w/ the JEMS Installer (using all the defaults)
2. Start the server
3. Drop my Ejb3Example-ds.xml file into the deploy folde
<?xml version="1.0" encoding="UTF-8"?>
|
| <datasources>
|
| <local-tx-datasource>
| <jndi-name>Ejb3ExampleDB</jndi-name>
| <connection-url>jdbc:hsqldb:${jboss.server.data.dir}${/}hypersonic${/}Ejb3ExampleDB</connection-url>
| <driver-class>org.hsqldb.jdbcDriver</driver-class>
| <user-name>sa</user-name>
| <password></password>
| <min-pool-size>5</min-pool-size>
| <max-pool-size>20</max-pool-size>
|
| <idle-timeout-minutes>0</idle-timeout-minutes>
| <track-statements />
| <security-domain>HsqlDbRealm</security-domain>
|
| <metadata>
| <type-mapping>Hypersonic SQL</type-mapping>
| </metadata>
|
| <depends>jboss:service=Hypersonic,database=Ejb3ExampleDB</depends>
|
| </local-tx-datasource>
|
| <!-- This mbean can be used when using in process persistent db -->
| <mbean code="org.jboss.jdbc.HypersonicDatabase"
| name="jboss:service=Hypersonic,database=Ejb3ExampleDB">
| <attribute name="Database">Ejb3ExampleDB</attribute>
| <attribute name="InProcessMode">true</attribute>
| </mbean>
|
| </datasources>
|
4. Build my application source and package it into a Jar including my persistence.xml (sp?) file within the META-INF directory
<?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="Ejb3Example">
|
| <provider>org.hibernate.ejb.HibernatePersistence</provider>
| <jta-data-source>java:/Ejb3ExampleDB</jta-data-source>
| <properties>
| <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect" />
| <property name="hibernate.hbm2ddl.auto" value="create-drop" />
| </properties>
|
| </persistence-unit>
|
| </persistence>
|
5. Drop my Jar into the deploy folder with my DAO class set up as follows:
@Stateful
| public class MyDaoBean implements MyDaoLocal, MyDaoRemote
| {
| @PersistenceContext(unitName = "Ejb3Example")
| private EntityManager entityManager;
|
| private Logger logger;
|
| @PostConstruct
| public void init() {
| // attribute initialization
| logger = Logger.getLogger("Ejb3ExampleStorageManager");
|
| // core logging
| logger.info("EJB 3 Example storage initialized.");
| logger.info("Storage flush mode: " + entityManager.getFlushMode());
| }
|
| public void ping() {
| logger.debug("Object Storage Ping");
| }
|
| public void create(Serializable obj) {
| logger.info("Persis requested for " + obj.getClass().getName());
| entityManager.persist(obj);
| }
|
| public <T> T find(Class<T> objectType, UUID primaryKey) {
| logger.info("Lookup requested for " + objectType.getName() + "/" + primaryKey);
| return entityManager.find(objectType, primaryKey);
| }
| }
The problems that I get are exceptions thrown apparently relating to authentication errors (larger stack trace available upon request):
...
| org.jboss.resource.JBossResourceException: No matching credentials in Subject!
| ...
| org.jboss.util.NestedSQLException: No matching credentials in Subject!; - nested throwable: (org.jboss.resource.JBossResourceException: No matching credentials in Subject!)
| ...
| Caused by: org.jboss.resource.JBossResourceException: No matching credentials in Subject!
| ... etc.
What am I doing wrong?
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4088033#4088033
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4088033
18 years, 7 months
[EJB 3.0] - EJB3 Entity doing Batch Insert fails with transaction requir
by ejb3workshop
I am reading a rather large XML file, split it into a large number of segments and would like to insert each segment into a database. The segments fit nicely into entities, so please don't tell me about prepared statement etc. Currently I have MDB which received the file descriptor and begins reading the file and processing it.
When using smaller files (<30Mb) everything seems to work really well. The files are loaded quickly and without errors. However as soon as the I try to load the large file the process failes with :
anonymous wrote :
| javax.persistence.TransactionRequiredException: EntityManager must be access within a transaction
| at org.jboss.ejb3.entity.ManagedEntityManagerFactory.verifyInTx(ManagedEntityManagerFactory.java:150)
| at org.jboss.ejb3.entity.TransactionScopedEntityManager.persist(TransactionScopedEntityManager.java:181)
| at com.thunderhead.backend.BatchJobDevider.segmentCompleted(BatchJobDevider.java:56)
| at com.thunderhead.backend.utilities.XMLSegmenter.notifyListeners(XMLSegmenter.java:61)
| at com.thunderhead.backend.utilities.XMLSegmenter.segment(XMLSegmenter.java:51)
| at com.thunderhead.backend.BatchJobProcessor.onMessage(BatchJobProcessor.java:85)
| at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
| at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
| at java.lang.reflect.Method.invoke(Method.java:597)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
| at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
| at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:126)
| at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:195)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.ejb3.mdb.MessagingContainer.localInvoke(MessagingContainer.java:245)
| at org.jboss.ejb3.mdb.inflow.MessageInflowLocalProxy.delivery(MessageInflowLocalProxy.java:268)
| at org.jboss.ejb3.mdb.inflow.MessageInflowLocalProxy.invoke(MessageInflowLocalProxy.java:138)
| at $Proxy99.onMessage(Unknown Source)
| at org.jboss.resource.adapter.jms.inflow.JmsServerSession.onMessage(JmsServerSession.java:178)
| at org.jboss.mq.SpyMessageConsumer.sessionConsumerProcessMessage(SpyMessageConsumer.java:891)
| at org.jboss.mq.SpyMessageConsumer.addMessage(SpyMessageConsumer.java:170)
| at org.jboss.mq.SpySession.run(SpySession.java:323)
| at org.jboss.resource.adapter.jms.inflow.JmsServerSession.run(JmsServerSession.java:237)
| at org.jboss.resource.work.WorkWrapper.execute(WorkWrapper.java:204)
| at org.jboss.util.threadpool.BasicTaskWrapper.run(BasicTaskWrapper.java:275)
| at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExecutor.java:743)
| at java.lang.Thread.run(Thread.java:619)
|
Currently I don't have any transaction attributes defined on my onMessage method. At first I thought it might be the database connection pool timing out, so I increased the timeout. However I now get this failure before the timeout period elapsed. It seems that the transaction constructed by the server is exceeding some limit and then enters into a no transaction available state.
Any suggestions on how to resolve this without using a prepared statement and inserting it directly into the database.
Thanks
Alex
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4088029#4088029
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4088029
18 years, 7 months
[JBoss jBPM] - Scheduler configuration
by lucdew
Hi,
i have problems trying to enable jbpm timers.
I declared the following configuration (which is copied from the default.jbpm.cfg.xml).
<!-- Jbpm job executor -->
| <bean name="jbpm.job.executor" class="org.jbpm.job.executor.JobExecutor">
| <field name="jbpmConfiguration"><ref bean="jbpmConfiguration" /></field>
| <field name="name"><string value="JbpmJobExector" /></field>
| <field name="nbrOfThreads"><int value="1" /></field>
| <field name="idleInterval"><int value="5000" /></field>
| <field name="maxIdleInterval"><int value="3600000" /></field> <!-- 1 hour -->
| <field name="historyMaxSize"><int value="20" /></field>
| <field name="maxLockTime"><int value="600000" /></field> <!-- 10 minutes -->
| <field name="lockMonitorInterval"><int value="60000" /></field> <!-- 1 minute -->
| <field name="lockBufferTime"><int value="5000" /></field> <!-- 5 seconds -->
| </bean>
The problem is that i get the following message:
anonymous wrote : 2007-09-24 17:20:23,709 INFO [STDOUT] WARN [main] org.jbpm.configuration.ObjectFactoryImpl - no info for object 'jbpmConfiguration'.
At deployment time i execute the following code to start the JobExecutorThread:
JbpmConfiguration configuration = JbpmConfiguration.getInstance();
| configuration.startJobExecutor();
I don't even understand how the default configuration can work since in the default configuration file there's no "jbpmConfiguration" bean defined.
This bean is a dependency of jbpm.job.executor bean.
I searched in the sources but haven't found any jbpmConfiguration bean key defined. Maybe it finds it by its type.
But the default configuration generates the following exceptions:
anonymous wrote : 2007-09-24 17:20:23,715 INFO [STDOUT] ERROR [JbpmJobExector:10.X.X.X:1] org.jbpm.job.executor.JobExecutorThread - exception in job executor thread. waiting 5000 milliseconds
| java.lang.NullPointerException
| at org.jbpm.job.executor.JobExecutorThread.acquireJobs(JobExecutorThread.java:106)
| at org.jbpm.job.executor.JobExecutorThread.run(JobExecutorThread.java:56)
| I need you help.
Thanks
Luc
(jbpm version 3.2.1)
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4088028#4088028
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4088028
18 years, 7 months