Hot questions for Using Enterprise JavaBeans in postgresql

Question:

I've got a bean definition with an entityManager like this:

@Stateless
public class JPABean<T> {

    private static final Logger LOG = Logger.getLogger(JPABean.class);

    @PersistenceContext(unitName = "myPersistanceSettings")
    private EntityManager em;

    public void write(T o) {
        LOG.info("PERSISTING");
        em.persist(o);
        LOG.info("FLASHING");
        em.flush();
        LOG.info("SUCCESS");
    }

My persistance.xml

<persistence-unit name="eSystemJPA" transaction-type="JTA" >
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <jta-data-source>java:jboss/datasources/myDS</jta-data-source>
    <properties>
        <property name="hibernate.show_sql" value="true" />
        <property name="hibernate.hbm2ddl.auto" value="validate" />
        <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
        <property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform" />
    </properties>
</persistence-unit>

My api:

@Path("activityAPI")
public class ActivityAPI {

    private static final Logger log = Logger.getLogger(ActivityAPI.class);

    @EJB
    private JPABean<ActivityLogEntry> activityJpa;

    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    public Response reportActivity(@Context HttpServletRequest hsr, final ActivityAPIRequest body) { ...

My standalone.xml with datasource:

    <datasource jta="true" jndi-name="java:jboss/datasources/myDS" pool-name="PostgrePool" enabled="true" spy="true" use-ccm="false">
            <connection-url>jdbc:postgresql://localhost/postgres</connection-url>
            <driver>postgres</driver>
            <pool>
                <min-pool-size>10</min-pool-size>
                <max-pool-size>100</max-pool-size>
                <prefill>true</prefill>
            </pool>
            <security>
                <user-name>postgres</user-name>
                <password>postgres</password>
            </security>
            <validation>
                <validate-on-match>false</validate-on-match>
                <background-validation>false</background-validation>
            </validation>
            <statement>
                <share-prepared-statements>false</share-prepared-statements>
            </statement>
        </datasource>

And i'm receiving:

2015-03-11 17:48:39,945 INFO    [JPABean.write]: PERSISTING
2015-03-11 17:48:39,946 INFO    [AbstractLoggingWriter.write]: INFO   [JPABean.write]: PERSISTING
2015-03-11 17:48:39,946 DEBUG   [TransactionCoordinatorImpl.attemptToRegisterJtaSync]: Skipping JTA sync registration due to auto join checking
2015-03-11 17:48:39,946 INFO    [AbstractLoggingWriter.write]: DEBUG  [TransactionCoordinatorImpl.attemptToRegisterJtaSync]: Skipping JTA sync registration due to auto join checking
2015-03-11 17:48:39,947 DEBUG   [TransactionCoordinatorImpl.attemptToRegisterJtaSync]: successfully registered Synchronization
2015-03-11 17:48:39,947 INFO    [AbstractLoggingWriter.write]: DEBUG  [TransactionCoordinatorImpl.attemptToRegisterJtaSync]: successfully registered Synchronization
2015-03-11 17:48:39,947 DEBUG   [AbstractEntityManagerImpl.joinTransaction]: Looking for a JTA transaction to join
2015-03-11 17:48:39,947 INFO    [AbstractLoggingWriter.write]: DEBUG  [AbstractEntityManagerImpl.joinTransaction]: Looking for a JTA transaction to join
2015-03-11 17:48:39,948 INFO    [AbstractLoggingWriter.write]: Hibernate: select nextval ('hibernate_sequence')
2015-03-11 17:48:39,949 DEBUG   [LogicalConnectionImpl.obtainConnection]: Obtaining JDBC connection
2015-03-11 17:48:39,949 INFO    [AbstractLoggingWriter.write]: DEBUG  [LogicalConnectionImpl.obtainConnection]: Obtaining JDBC connection
2015-03-11 17:48:39,950 DEBUG   [LogicalConnectionImpl.obtainConnection]: Obtained JDBC connection
2015-03-11 17:48:39,950 INFO    [AbstractLoggingWriter.write]: DEBUG  [LogicalConnectionImpl.obtainConnection]: Obtained JDBC connection
2015-03-11 17:48:39,952 DEBUG   [LogicalConnectionImpl.releaseConnection]: Releasing JDBC connection
2015-03-11 17:48:39,952 INFO    [AbstractLoggingWriter.write]: DEBUG  [LogicalConnectionImpl.releaseConnection]: Releasing JDBC connection
2015-03-11 17:48:39,953 DEBUG   [LogicalConnectionImpl.releaseConnection]: Released JDBC connection
2015-03-11 17:48:39,953 INFO    [AbstractLoggingWriter.write]: DEBUG  [LogicalConnectionImpl.releaseConnection]: Released JDBC connection
2015-03-11 17:48:39,954 INFO    [JPABean.write]: FLASHING
2015-03-11 17:48:39,955 INFO    [AbstractLoggingWriter.write]: INFO   [JPABean.write]: FLASHING
2015-03-11 17:48:39,957 INFO    [AbstractLoggingWriter.write]: DEBUG  [ActivityAPI.reportActivity]: POST Received PUT reportActivity
2015-03-11 17:48:39,957 DEBUG   [EntityPrinter.toString]: Listing entities:
2015-03-11 17:48:39,957 INFO    [AbstractLoggingWriter.write]: DEBUG  [EntityPrinter.toString]: Listing entities:
2015-03-11 17:48:39,958 DEBUG   [EntityPrinter.toString]: ActivityLogEntry{... body ...}
2015-03-11 17:48:39,958 INFO    [AbstractLoggingWriter.write]: DEBUG  [EntityPrinter.toString]: ActivityLogEntry{... body ...}
2015-03-11 17:48:39,959 INFO    [JPABean.write]: PERSISTING
2015-03-11 17:48:39,959 INFO    [AbstractLoggingWriter.write]: INFO   [JPABean.write]: PERSISTING
2015-03-11 17:48:39,962 INFO    [AbstractLoggingWriter.write]: Hibernate: insert into activity_log_entry (all columns) values (?, ?, ?, ?, ?, ?, ?, ?, ?)

So in fact there is a problem with persisting (inserting) 2 entities into a table. I was trying to add @Transactional annotation on my public writing method and on my api, but it doesn't work. I was trying also with @TransactionAttribute(TransactionAttributeType.REQUIRED), but it's still the same. Also using EntityManagerFactory to create entityManager doesn't work (documentation says that entityManager is not thread-safe, but EntityManagerFactory is thread-safe). I'm using:

postgressql - 9.3 jboss-ejb-api_3.2_spec jboss-servlet-api_3.1_spec resteasy-jaxrs hibernate-entitymanager hibernate-validator driver postresql>9.3-1102-jdbc41 wildfly 8.2 or wildfly 8.0

logs from hibernate:

2015-03-11 17:53:39,947 WARN    [SynchronizationCallbackCoordinatorTrackingImpl.afterCompletion]: HHH000451: Transaction afterCompletion called by a background thread; delaying afterCompletion processing until the original thread can handle it. [status=4]

Trace from wildfly

17:53:39,944 WARN  [com.arjuna.ats.arjuna] (Transaction Reaper) ARJUNA012117: TransactionReaper::check timeout for TX 0:ffff7f000001:62455507:550071b3:35 in state  RUN
    17:53:39,945 WARN  [com.arjuna.ats.arjuna] (Transaction Reaper Worker 0) ARJUNA012095: Abort of action id 0:ffff7f000001:62455507:550071b3:35 invoked while multiple threads active within it.
    17:53:39,946 WARN  [com.arjuna.ats.arjuna] (Transaction Reaper Worker 0) ARJUNA012108: CheckedAction::check - atomic action 0:ffff7f000001:62455507:550071b3:35 aborting with 1 threads active!
    17:53:39,957 WARN  [com.arjuna.ats.arjuna] (Transaction Reaper) ARJUNA012117: TransactionReaper::check timeout for TX 0:ffff7f000001:62455507:550071b3:3b in state  RUN
    17:53:40,445 WARN  [com.arjuna.ats.arjuna] (Transaction Reaper) ARJUNA012117: TransactionReaper::check timeout for TX 0:ffff7f000001:62455507:550071b3:35 in state  CANCEL
    17:53:40,446 WARN  [com.arjuna.ats.arjuna] (Transaction Reaper) ARJUNA012378: ReaperElement appears to be wedged: org.apache.log4j.AppenderSkeleton.doAppend(AppenderSkeleton.java:231)
    org.apache.log4j.JBossAppenderHandler.doPublish(JBossAppenderHandler.java:42)
    org.jboss.logmanager.ExtHandler.publish(ExtHandler.java:79)
    org.jboss.logmanager.LoggerNode.publish(LoggerNode.java:296)
    org.jboss.logmanager.LoggerNode.publish(LoggerNode.java:304)
    org.jboss.logmanager.LoggerNode.publish(LoggerNode.java:304)
    org.jboss.logmanager.LoggerNode.publish(LoggerNode.java:304)
    org.jboss.logmanager.LoggerNode.publish(LoggerNode.java:304)
    org.jboss.logmanager.LoggerNode.publish(LoggerNode.java:304)
    org.jboss.logmanager.LoggerNode.publish(LoggerNode.java:304)
    org.jboss.logmanager.LoggerNode.publish(LoggerNode.java:304)
    org.jboss.logmanager.Logger.logRaw(Logger.java:721)
    org.jboss.logmanager.Logger.log(Logger.java:672)
    org.jboss.logging.JBossLogManagerLogger.doLogf(JBossLogManagerLogger.java:50)
    org.jboss.logging.Logger.logf(Logger.java:2096)
    org.hibernate.internal.CoreMessageLogger_$logger.rollbackFromBackgroundThread(CoreMessageLogger_$logger.java:1032)
    org.hibernate.engine.transaction.synchronization.internal.SynchronizationCallbackCoordinatorTrackingImpl.afterCompletion(SynchronizationCallbackCoordinatorTrackingImpl.java:85)
    org.hibernate.engine.transaction.synchronization.internal.RegisteredSynchronization.afterCompletion(RegisteredSynchronization.java:56)
    com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple.afterCompletion(SynchronizationImple.java:96)
    com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.afterCompletion(TwoPhaseCoordinator.java:532)
    com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.afterCompletion(TwoPhaseCoordinator.java:463)
    com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.cancel(TwoPhaseCoordinator.java:118)
    com.arjuna.ats.arjuna.AtomicAction.cancel(AtomicAction.java:215)
    com.arjuna.ats.arjuna.coordinator.TransactionReaper.doCancellations(TransactionReaper.java:377)
    com.arjuna.ats.internal.arjuna.coordinator.ReaperWorkerThread.run(ReaperWorkerThread.java:78)

    17:53:40,457 WARN  [com.arjuna.ats.arjuna] (Transaction Reaper) ARJUNA012117: TransactionReaper::check timeout for TX 0:ffff7f000001:62455507:550071b3:3b in state  SCHEDULE_CANCEL
    17:53:40,947 WARN  [com.arjuna.ats.arjuna] (Transaction Reaper) ARJUNA012117: TransactionReaper::check timeout for TX 0:ffff7f000001:62455507:550071b3:35 in state  CANCEL_INTERRUPTED
    17:53:40,948 WARN  [com.arjuna.ats.arjuna] (Transaction Reaper) ARJUNA012120: TransactionReaper::check worker Thread[Transaction Reaper Worker 0,5,main] not responding to interrupt when cancelling TX 0:ffff7f000001:62455507:550071b3:35 -- worker marked as zombie and TX scheduled for mark-as-rollback
    17:53:40,949 WARN  [com.arjuna.ats.arjuna] (Transaction Reaper) ARJUNA012110: TransactionReaper::check successfuly marked TX 0:ffff7f000001:62455507:550071b3:35 as rollback only
    17:53:40,948 WARN  [com.arjuna.ats.arjuna] (Transaction Reaper Worker 1) ARJUNA012095: Abort of action id 0:ffff7f000001:62455507:550071b3:3b invoked while multiple threads active within it.
    17:53:40,949 WARN  [com.arjuna.ats.arjuna] (Transaction Reaper Worker 1) ARJUNA012108: CheckedAction::check - atomic action 0:ffff7f000001:62455507:550071b3:3b aborting with 1 threads active!
    17:53:40,949 WARN  [com.arjuna.ats.arjuna] (Transaction Reaper Worker 1) ARJUNA012121: TransactionReaper::doCancellations worker Thread[Transaction Reaper Worker 1,5,main] successfully canceled TX 0:ffff7f000001:62455507:550071b3:3b

I also saw that my transcations are in idle state in postgressql:

"idle in transaction";"select nextval ('hibernate_sequence')"
"idle in transaction";"select nextval ('hibernate_sequence')"

Every suggestion will be extremely helpful for me :)


Answer:

org.apache.log4j.JBossAppenderHandler.doPublish(JBossAppenderHandler.java:42)

This line was a little bit meaningless for me, but recently I find out the meaning... I had a structure of my project with log4j.xml inside WebContent/META-INF folder and i was using org.jboss.logging.Logger. Unfortunately i didn't get any error but the location of this file was wrong. As documentation says: https://docs.jboss.org/process-guide/en/html/logging.html

The log4j configuration is loaded from the jboss server conf/log4j.xml file.

I recognize that problem is connected exactly with org.apache.log4j.ConsoleAppender. After removed it I don't have any problem with multithreading now and I don't need any annotation cause @TransactionalAttribute() is on default set as required. Also there is no need to use EntityManagerFactory even if EntityManager is not thread-safe.

Take a look on that: Log4j is hanging my application what am I doing wrong?

Question:

The question itself will be updated along until the error is clear.

We recently did an upgrade on our system a few months back from JBoss to Wildfly and our system has gone buggy ever since.

Lets say I have the following tables

CREATE TABLE students(
    ID int,
    Classid int,
    Name varchar(50),
    Version int
)

CREATE TABLE classstudent(
    ID int,
    Classname varchar(50),
    Version int
)

I write the following query and it worked

select *
from students

I write the following but it doesnt work

select *
from students s
join classStudent cs on cs.id = s.classid

So I decided to select each field

select s.id,s.classid,c.name,s.version,cs.id,cs.classname,cs.version
from students s
join classStudent cs on cs.id = s.classid

I still get an error so I decided to select the 2 ids from each table

select s.id,cs.id
from students s
join classStudent cs on cs.id = s.classid

I got an error one more time but then I renamed the ids to different names

select s.id as sid,cs.id as csid
from students s
join classStudent cs on cs.id = s.classid

This query worked, so clearly whenever there are identical field names on either table, the system throws an error.

What is this problem and how can I solve this problem? Where should I start looking? Any link to help point me in the right direction would be greatful!

error
----

WFLYEJB0443: EJB 3.1 FR 13.3.3: BMT bean SqlSearchExecutionSessionBean should complete transaction before returning.

As I said however before, this is a general error and I sometimes get it too when I misspell a table name or field name!


Answer:

Your query result can't have identical column names as a result. So the column name id can only exist once in your SELECT statement.

Therefore I would try this:

select s.id, s.classid, c.name, s.version, cs.classname, cs.version
from Students s
join ClassStudent cs on cs.id = s.classid

In here you don't have to mention cs.id since it is always equal to s.id as it is in your join statement. However, if you do want it in your query you could give it an alias like this cs.id AS csid (or some other unused name) and add this to your SELECT statement.

Question:

I have an app deployed on Websphere container and configured the EJB Timer scheduler through the container.

I have an oracle DB configured and all is working smoothly.

Now i'm trying to change the DB from Oracle to postgres SQL and did all the needed work including creating new data source, drivers, etc. The Websphere did managed to connect to the DB through the Datasource. I'm Using the same Jndi as i had with my oracle db so no extra work needed in the code.

When i'm trying to start the application and install new EAR file i'm getting the following exception:

WebSphere:name=ApplicationManager,process=server1,platform=proxy,node=localhostNode01,version=8.5.5.10,type=ApplicationManager,mbeanIdentifier=ApplicationManager,cell=localhostNode01Cell,spec=1.0 exception is: javax.management.MBeanException: Exception thrown in RequiredModelMBean while trying to invoke operation startApplication at javax.management.modelmbean.RequiredModelMBean.invokeMethod(RequiredModelMBean.java:1304) at javax.management.modelmbean.RequiredModelMBean.invoke(RequiredModelMBean.java:1093) at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:832) at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:814) at com.ibm.ws.management.AdminServiceImpl$1.run(AdminServiceImpl.java:1350) at com.ibm.ws.security.util.AccessController.doPrivileged(AccessController.java:118) at com.ibm.ws.management.AdminServiceImpl.invoke(AdminServiceImpl.java:1243) at com.ibm.ws.management.application.AppManagementImpl._startApplication(AppManagementImpl.java:1482) at com.ibm.ws.management.application.AppManagementImpl.startApplication(AppManagementImpl.java:1371) at com.ibm.ws.management.application.AppManagementImpl.startApplication(AppManagementImpl.java:1320) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:95) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:56) at java.lang.reflect.Method.invoke(Method.java:620) at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:88) at sun.reflect.GeneratedMethodAccessor31.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:56) at java.lang.reflect.Method.invoke(Method.java:620) at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:292) at javax.management.modelmbean.RequiredModelMBean$4.run(RequiredModelMBean.java:1261) at java.security.AccessController.doPrivileged(AccessController.java:422) at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:88) at javax.management.modelmbean.RequiredModelMBean.invokeMethod(RequiredModelMBean.java:1255) at javax.management.modelmbean.RequiredModelMBean.invoke(RequiredModelMBean.java:1093) at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:832) at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:814) at com.ibm.ws.management.AdminServiceImpl$1.run(AdminServiceImpl.java:1350) at com.ibm.ws.security.util.AccessController.doPrivileged(AccessController.java:118) at com.ibm.ws.management.AdminServiceImpl.invoke(AdminServiceImpl.java:1243) at com.ibm.ws.management.connector.AdminServiceDelegator.invoke(AdminServiceDelegator.java:181) at sun.reflect.GeneratedMethodAccessor38.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:56) at java.lang.reflect.Method.invoke(Method.java:620) at com.ibm.ws.management.connector.soap.SOAPConnector.invoke(SOAPConnector.java:488) at com.ibm.ws.management.connector.soap.SOAPConnector.service(SOAPConnector.java:324) at com.ibm.ws.management.connector.soap.SOAPConnection.handleRequest(SOAPConnection.java:65) at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:733) at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:522) at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1892) Caused by: com.ibm.ws.exception.RuntimeError: com.ibm.websphere.csi.EJBContainerException: EJB Timer Service not started at com.ibm.ws.ejbcontainer.runtime.AbstractEJBRuntime.startModule(AbstractEJBRuntime.java:731) at com.ibm.ws.ejbcontainer.runtime.SharedEJBRuntimeImpl.startModule(SharedEJBRuntimeImpl.java:338) at com.ibm.ws.runtime.component.EJBContainerImpl.start(EJBContainerImpl.java:3588) at com.ibm.ws.runtime.component.ApplicationMgrImpl.start(ApplicationMgrImpl.java:1179) at com.ibm.ws.runtime.component.DeployedApplicationImpl.fireDeployedObjectStart(DeployedApplicationImpl.java:1390) at com.ibm.ws.runtime.component.DeployedModuleImpl.start(DeployedModuleImpl.java:639) at com.ibm.ws.runtime.component.DeployedApplicationImpl.start(DeployedApplicationImpl.java:979) at com.ibm.ws.runtime.component.ApplicationMgrImpl.startApplication(ApplicationMgrImpl.java:778) at com.ibm.ws.runtime.component.ApplicationMgrImpl.startApplicationDynamically(ApplicationMgrImpl.java:1381) at com.ibm.ws.runtime.component.ApplicationMgrImpl.start(ApplicationMgrImpl.java:2192) at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.start(CompositionUnitMgrImpl.java:435) at com.ibm.ws.runtime.component.CompositionUnitImpl.start(CompositionUnitImpl.java:123) at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.start(CompositionUnitMgrImpl.java:378) at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.access$500(CompositionUnitMgrImpl.java:126) at com.ibm.ws.runtime.component.CompositionUnitMgrImpl$1.run(CompositionUnitMgrImpl.java:653) at com.ibm.ws.security.auth.ContextManagerImpl.runAs(ContextManagerImpl.java:5396) at com.ibm.ws.security.auth.ContextManagerImpl.runAsSystem(ContextManagerImpl.java:5612) at com.ibm.ws.security.core.SecurityContext.runAsSystem(SecurityContext.java:255) at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.startCompositionUnit(CompositionUnitMgrImpl.java:667) at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.startCompositionUnit(CompositionUnitMgrImpl.java:611) at com.ibm.ws.runtime.component.ApplicationMgrImpl.startApplication(ApplicationMgrImpl.java:1271) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:95) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:56) at java.lang.reflect.Method.invoke(Method.java:620) at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:88) at sun.reflect.GeneratedMethodAccessor31.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:56) at java.lang.reflect.Method.invoke(Method.java:620) at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:292) at javax.management.modelmbean.RequiredModelMBean$4.run(RequiredModelMBean.java:1261) at java.security.AccessController.doPrivileged(AccessController.java:422) at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:88) at javax.management.modelmbean.RequiredModelMBean.invokeMethod(RequiredModelMBean.java:1255) ... 38 more Caused by: com.ibm.websphere.csi.EJBContainerException: EJB Timer Service not started at com.ibm.ws.runtime.component.EJBContainerImpl.getSchedulerInstance(EJBContainerImpl.java:2082) at com.ibm.ws.runtime.component.EJBContainerImpl.initializeTimerService(EJBContainerImpl.java:1827) at com.ibm.ws.runtime.component.WASEJBRuntimeImpl.initializeTimerService(WASEJBRuntimeImpl.java:540) at com.ibm.ws.ejbcontainer.runtime.AbstractEJBRuntime.startModule(AbstractEJBRuntime.java:575) ... 71 more Caused by: com.ibm.ws.scheduler.exception.SchedulerDataStoreException: com.ibm.ws.extensionhelper.exception.UnknownDatabaseException: Could not detect database vendor. Vendor string was PostgreSQL at com.ibm.ws.scheduler.WASSchedulerCfgHelper.createTables(WASSchedulerCfgHelper.java:546) at com.ibm.ws.runtime.component.EJBContainerImpl.createTimerTables(EJBContainerImpl.java:2712) at com.ibm.ws.runtime.component.EJBContainerImpl.getSchedulerInstance(EJBContainerImpl.java:2025) ... 74 more Caused by: com.ibm.ws.extensionhelper.exception.UnknownDatabaseException: Could not detect database vendor. Vendor string was PostgreSQL at com.ibm.ws.extensionhelper.db.impl.DatabaseHelperImpl.connect(DatabaseHelperImpl.java:672) at com.ibm.ws.extensionhelper.db.impl.DatabaseHelperImpl.initialize(DatabaseHelperImpl.java:501) at com.ibm.ws.extensionhelper.db.impl.DatabaseHelperImpl.(DatabaseHelperImpl.java:261) at com.ibm.ws.extensionhelper.impl.ExtensionHelperServiceImpl.getDatabaseHelper(ExtensionHelperServiceImpl.java:116) at com.ibm.ws.scheduler.DBHelperImpl.(DBHelperImpl.java:108) at com.ibm.ws.scheduler.WASSchedulerCfgHelper.getDatabaseHelper(WASSchedulerCfgHelper.java:959) at com.ibm.ws.scheduler.WASSchedulerCfgHelper.createTables(WASSchedulerCfgHelper.java:541) ... 76 more

[10/3/17 16:19:42:601 IDT] 00000067 ServletWrappe

I thought that after getting rid of the IBM scheduler and moving the the EJB standard Timer i won't get this exception.

Any idea how can i overcome this one?


Answer:

The implementation of EJB Persistent Timers is still backed by a database, so the capability is limited by which database vendors the application server has built-in interoperability with (SQL commands differ greatly across different database vendors). WebSphere Application Server traditional doesn't have have built in interoperability with PostgreSQL for EJB persistent timers (or for its Scheduler), which is why you see the error:

UnknownDatabaseException: Could not detect database vendor. Vendor string was PostgreSQL

That said, you might be able to get PostgreSQL to work for EJB Persistent Timers on WebSphere Application Server Liberty (as opposed to traditional) because the Liberty implementation is built on JPA rather than SQL.

Question:

I have a project which uses EJB3 and when the code throws an exception related to SQL, it sends a notification to the development team. So, for example, with this code:

Query q = getEntityManager().createNativeQuery(query);
List<Object[]> results = q.getResultList();

if I make a syntax error, I catch the first exception java.lang.IllegalArgumentException: Parameter with that position [2] did not exist which is sent to devs. Inside Eclipse I can see other exceptions like javax.ejb.EJBException: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not extract ResultSet and finally the last one with the message I want to catch: Caused by: org.postgresql.util.PSQLException: ERROR: syntax error at or near "AND". Is there a way to get this more details message? I can see that suppressed exceptions array is empty.

UPDATE: if I insert directly org.postgresql.util.PSQLException in catch, Eclipse states that:

This exception is never thrown from the try statement body


Answer:

The exceptions you see in the Eclipse stracktrace are exceptions stored in the IllegalArgumentException forming a chain of error causes.

You can get to the postgres exception by traversing this cause chain:

catch(IllegalArgumentException e) {
    Throwable t = e;
    while (t != null)
    {
        if (t instanceof PSQLException) {
              PSQLException pe = (PSQLException)t;
             // analyse the exception
             break;
        }
        t = t.getCause();
    }
}

Question:

Long story short:

  • Recipe contains

    @OneToMany(cascade = {CascadeType.MERGE, CascadeType.REMOVE}, mappedBy = "recipe")
    private Set<RecipeRow> rows = new HashSet<>();
    
  • Row contains:

    @ManyToOne(cascade = CascadeType.REFRESH)`
    @JoinColumn(name = "recipe_id")
    private Recipe recipe;`
    
  • The Row extends a mapped superclass with a tree structure (i.e. it contains a mapped parent field which is of same type)

Right before the entity manager merge (of the recipe) all rows (and their information) are there. When it merges, it throws this (it's with regards to the row!!!):

Caused by: org.postgresql.util.PSQLException: ERROR: null value in column "name" violates
    not-null constraint Detail: Failing row contains (11, 2015-08-22 13:53:33.276, 
    304170813849900523, 0, null, null, null, null, null, null, 1000, null, 
    null, null, null, null, null, null, null, null).

which is pretty much impossible because all mandatory fields are there.

Also, the ID sequence (of the row table) is increased, but no rows are persisted in the DB (postgres).

Am I missing something here? Is my question too broad?


Edit 1:

  • The JPA UID in the error message DOES NOT correspond to either of my recipe rows which are being saved. Where does this ghost entity come from?
  • All mandatory fields are filled in the rows before saving!

Answer:

Alright, so this was a beginner's mistake, and also a stupid one.

The rows have a tree structure, right? And the saved collection contained ALL of them, as flat tree (ie list).

The problem is that the top rows had the abstract root as parent (which isn't transient), and the abstract root was trying to map itself.

Of course I didn't notice this in the debugging, because I was only looking at the rows, and at their mandatory fields, but not at the parent (which isn't mandatory).

Yep...