Tuesday, 3 December 2019

JPA Exceptions and Solutions

Faced following exceptions during first time use and solutions with the same:

Exception in thread "main" javax.persistence.PersistenceException: [PersistenceUnit: IntegratorMasterdataPU] Unable to build Hibernate SessionFactory
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(EntityManagerFactoryBuilderImpl.java:1225)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.access$600(EntityManagerFactoryBuilderImpl.java:119)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:853)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:843)
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:399)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:842)
at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:73)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:78)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
at com.gaivery.App.main(App.java:16)
Caused by: org.hibernate.AnnotationException: No identifier specified for entity: com.gaivery.integrator.bnow.dao.model.CustomerAgreementComputerAttachments
at org.hibernate.cfg.InheritanceState.determineDefaultAccessType(InheritanceState.java:277)
at org.hibernate.cfg.InheritanceState.getElementsToProcess(InheritanceState.java:224)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:732)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:3762)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3716)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1410)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1844)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850)
... 7 more

-------------

Caused by: org.hibernate.AnnotationException: @Temporal should only be set on a java.util.Date or java.util.Calendar property: com.gaivery.integrator.bnow.dao.model.CustomerAgreement.activePeriodFrom

String and Temporal does not work together. Changed type to Date


Caused by: org.hibernate.AnnotationException: Illegal attempt to map a non collection as a @OneToMany, @ManyToMany or @CollectionOfElements: com.gaivery.integrator.bnow.dao.model.CustomerAgreement.agreementPeriods

private CustomerAgreementPeriod agreementPeriods;
private List<CustomerAgreementPeriod> agreementPeriods;


Exception in thread "main" java.lang.NoSuchMethodError: javax.persistence.Table.indexes()[Ljavax/persistence/Index;

Moved to previous version 4.2.8 as it is found that 4.3.0 is compatible with 2.1 persistance version but we were using 2.0

--------------------
Caused by: org.hibernate.AnnotationException: @OneToOne or @ManyToOne on com.gaivery.integrator.bnow.dao.model.CustomerAgreement.customerId references an unknown entity: java.lang.String

It was mentioned String but it should mention entity class to which it is returning the data.

--------------------
Caused by: org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: com.gaivery.integrator.bnow.dao.model.CustomerAgreementPeriod.customerAgreementPeriod in com.gaivery.integrator.bnow.dao.model.CustomerAgreement.agreementPeriods

It is corrected when name of current entity is  given in mappedBy
@OneToMany(mappedBy = "customerAgreement", orphanRemoval = true, fetch = FetchType.LAZY, cascade = {CascadeType.ALL})
private List<CustomerAgreementCustom> customFields;

--------------------
Caused by: org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: com.gaivery.integrator.bnow.dao.model.CustomerAgreementRoles.customerAgreement in com.gaivery.integrator.bnow.dao.model.CustomerAgreement.restrictedToRoles
at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:708)

Setter was not in place in @ManyToOne

--------------------
Caused by: org.hibernate.MappingException: Composite-id class must implement Serializable: com.gaivery.integrator.bnow.dao.model.CustomerAgreementCustom

Implements serializable and added serialVersionId
--------------------
Nov 28, 2019 10:25:24 AM org.hibernate.mapping.RootClass checkCompositeIdentifier
WARN: HHH000038: Composite-id class does not override equals(): com.gaivery.integrator.bnow.dao.model.CustomerAgreementCustom
Nov 28, 2019 10:25:24 AM org.hibernate.mapping.RootClass checkCompositeIdentifier
WARN: HHH000039: Composite-id class does not override hashCode(): com.gaivery.integrator.bnow.dao.model.CustomerAgreementCustom
Nov 28, 2019 10:25:24 AM org.hibernate.mapping.RootClass checkCompositeIdentifier
WARN: HHH000038: Composite-id class does not override equals(): com.gaivery.integrator.bnow.dao.model.CustomerAgreementRoles
Nov 28, 2019 10:25:24 AM org.hibernate.mapping.RootClass checkCompositeIdentifier
WARN: HHH000039: Composite-id class does not override hashCode(): com.gaivery.integrator.bnow.dao.model.CustomerAgreementRoles
Nov 28, 2019 10:25:24 AM org.hibernate.mapping.RootClass checkCompositeIdentifier
WARN: HHH000038: Composite-id class does not override equals(): com.gaivery.integrator.bnow.dao.model.CustomerAgreementPeriod
Nov 28, 2019 10:25:24 AM org.hibernate.mapping.RootClass checkCompositeIdentifier
WARN: HHH000039: Composite-id class does not override hashCode(): com.gaivery.integrator.bnow.dao.model.CustomerAgreementPeriod

Added Hashcode and equals
-------------------
Exception in thread "main" java.lang.NullPointerException
at org.hibernate.engine.transaction.internal.jta.JtaStatusHelper.getStatus(JtaStatusHelper.java:73)
at org.hibernate.engine.transaction.internal.jta.JtaStatusHelper.isActive(JtaStatusHelper.java:115)
at org.hibernate.engine.transaction.internal.jta.CMTTransaction.join(CMTTransaction.java:149)
at org.hibernate.ejb.AbstractEntityManagerImpl.joinTransaction(AbstractEntityManagerImpl.java:1230)
at org.hibernate.ejb.AbstractEntityManagerImpl.postInit(AbstractEntityManagerImpl.java:178)
at org.hibernate.ejb.EntityManagerImpl.<init>(EntityManagerImpl.java:89)
at org.hibernate.ejb.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:193)
at org.hibernate.ejb.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:188)
at com.gaivery.App.main(App.java:17)

Earlier transaction-type="JTA" >

Changed it to RESOURCE_LOCAL

-----------------------

Hibernate TABLES NOT GETTING CREATED

Earlier -> <property name="hbm2ddl.auto" value="create" />

JUST CHANGED IT TO <property name="hibernate.hbm2ddl.auto" value="create" /> AND DONE

The reference suggests it should be hibernate.hbm2ddl.auto
A value of create will create your tables at sessionFactory creation, and leave them intact.
A value of create-drop will create your tables, and then drop them when you close the sessionFactory.

------------------------------

Caused by: org.hibernate.AnnotationException: No identifier specified for entity: com.gaivery.integrator.bnow.dao.model.CustomerAgreementComputerAttachments

@Id
@ManyToOne
    @JoinColumn(name = "id")

@Id was missing before


-------------------------------------

Caused by: java.lang.IllegalStateException: org.hibernate.TransientPropertyValueException: object references an unsaved transient instance - save the transient instance before flushing : com.gaivery.integrator.bnow.model.CustomerAgreement.customerId -> com.gaivery.integrator.bnow.model.bnowCustomers

When you try to perisst parent entity from child using New Parent()

-------------------------------------

Caused by: java.sql.SQLIntegrityConstraintViolationException: ORA-02291: integrity constraint (MASTERDATA.FK_I0VXQXGAG2ISERDDTE3XNQ1OY) violated - parent key not found

When try to insert ID but no parent record exist yet

-------------------------------------

java.sql.SQLIntegrityConstraintViolationException: ORA-00001: unique constraint (MASTERDATA.SYS_C0021188) violated

Why try to reinsert with same ID

------------------------------------

Exception in thread "main" javax.persistence.RollbackException: Error while committing the transaction
at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:92)
at com.gaivery.App.main(App.java:30)
Caused by: javax.persistence.PersistenceException: org.hibernate.HibernateException: A collection with cascade="all-delete-orphan" was no longer referenced by the owning entity instance: com.gaivery.integrator.bnow.dao.model.CustomerAgreement.autoAttachComputersFromOrganizations
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1387)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1310)
at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:80)
... 1 more
Caused by: org.hibernate.HibernateException: A collection with cascade="all-delete-orphan" was no longer referenced by the owning entity instance: com.gaivery.integrator.bnow.dao.model.CustomerAgreement.autoAttachComputersFromOrganizations

Need to find and merge

MERGE will shoot 2 Queries
FIND AND MERGE will shoot 2 queries in total.
No Updates in Object will not shoot Merge at all

em = emf.createEntityManager();
        CustomerAgreement cAgreement = em.find(CustomerAgreement.class, 32121212l);
        //CustomerAgreement cAgreement = new CustomerAgreement();
        //cAgreement.setId(32121212l);
        cAgreement.setName("singh");;
        cAgreement.setCustomerId("140");
        em.getTransaction().begin();
        em.merge(cAgreement);
        em.getTransaction().commit();;

Monday, 21 April 2014

Mule: How to parse HTTP Query String in Mule?

URL: /GetMonitoringInfo?IP=10.2.2.12

Mule Expression Language:
#[message.inboundProperties['http.query.params']['IP']]

In Flow:
<logger message="#[message.inboundProperties['http.query.params']['IP']] " level="INFO" doc:name="Logger"/>

Output: 10.2.2.12 

Thursday, 27 March 2014

Deploy to remote Glassfish Server using Netbeans

Are you getting following error while connecting to remote Glassfish using Netbeans?

localhostFAIL:28080

or

server did not start. domainname would not start.


Monday, 24 June 2013

How to run Procedure in SQL Developer?

  • Use following script

          DECLARE
              x CLOB;
         BEGIN
             appps.GOODS_PKG.get_goods (704381009698,x);
            dbms_output.put_line(x);
         END;



  • In DBMS OUTPUT tab (present in tab panel where other results are shown), first press gTalk looking button on left which is enabling DBMS output.

  • After enabling Simple run above script and you will get output in DBMS OUTPUT TAB and also get successful running of procedure in RESULS tab.


Friday, 21 June 2013

java.io.IOException: An existing connection was forcibly closed by the remote host - Web Services

Client Side
  • Called a web service operation
  • Waiting for response
  • In between felt bored and cancelled it
  • I got no exception as client
  • I Sleep
Server Side
  • Got request
  • Called my methods to give output to client
  • Got result from methods and just was sending to client
WTF!!!!!
  • Client is unavailable so:
WARNING: StandardWrapperValve[EC3Monitoring]: PWC1406: Servlet.service() for servlet EC3Monitoring threw exception
java.io.IOException: An existing connection was forcibly closed by the remote host
    at sun.nio.ch.SocketDispatcher.write0(Native Method)
    at sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:33)
    at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:104)
    at sun.nio.ch.IOUtil.write(IOUtil.java:75)
    at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:334)
    at com.sun.grizzly.util.OutputWriter.flushChannel(OutputWriter.java:108)
    at com.sun.grizzly.util.OutputWriter.flushChannel(OutputWriter.java:76)
    at com.sun.grizzly.http.SocketChannelOutputBuffer.flushChannel(SocketChannelOutputBuffer.java:426)
    at com.sun.grizzly.http.SocketChannelOutputBuffer.flushBuffer(SocketChannelOutputBuffer.java:498)
    at com.sun.grizzly.http.SocketChannelOutputBuffer.flush(SocketChannelOutputBuffer.java:476)
    at com.sun.grizzly.http.ProcessorTask.action(ProcessorTask.java:1287)
    at com.sun.grizzly.tcp.Response.action(Response.java:268)
    at org.apache.catalina.connector.OutputBuffer.doFlush(OutputBuffer.java:380)
    at org.apache.catalina.connector.OutputBuffer.flush(OutputBuffer.java:353)
    at org.apache.catalina.connector.CoyoteOutputStream.flush(CoyoteOutputStream.java:175)
    at com.ctc.wstx.io.UTF8Writer.flush(UTF8Writer.java:103)
    at com.ctc.wstx.sw.BufferingXmlWriter.flush(BufferingXmlWriter.java:225)
    at com.ctc.wstx.sw.BaseStreamWriter.flush(BaseStreamWriter.java:261)
    at com.sun.xml.ws.util.xml.XMLStreamWriterFilter.flush(XMLStreamWriterFilter.java:71)
    at com.sun.xml.ws.streaming.XMLStreamWriterUtil.getOutputStream(XMLStreamWriterUtil.java:103)
    at com.sun.xml.ws.message.jaxb.JAXBMessage.writePayloadTo(JAXBMessage.java:382)
    at com.sun.xml.ws.message.AbstractMessageImpl.writeTo(AbstractMessageImpl.java:149)
    at com.sun.xml.ws.encoding.StreamSOAPCodec.encode(StreamSOAPCodec.java:127)
    at com.sun.xml.ws.encoding.SOAPBindingCodec.encode(SOAPBindingCodec.java:285)
    at com.sun.xml.ws.transport.http.HttpAdapter.encodePacket(HttpAdapter.java:421)
    at com.sun.xml.ws.transport.http.HttpAdapter.access$100(HttpAdapter.java:99)
    at com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:650)
    at com.sun.xml.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:263)
    at com.sun.xml.ws.transport.http.servlet.ServletAdapter.handle(ServletAdapter.java:163)
    at org.glassfish.webservices.JAXWSServlet.doPost(JAXWSServlet.java:145)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:688)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
    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:619)

Thursday, 20 June 2013

Add Socks Proxy Settings in SQL Developer

Sometime while connecting we get following exception:
        Software caused connection abort: recv failed 

Following is way to resolve this
  • Go to Following Path: 
Installation directory\sqldeveloper\ide\bin

  • Open ide.conf 

  • Add following
          AddVMOption -DsocksProxyHost=localhost 
          AddVMOption -DsocksProxyPort=12345

  • Start SQL Developer

Tuesday, 19 March 2013

serialVersionUID What is that?

The serialVersionUID is used as a version control in a Serializable class. If you do not explicitly declare a serialVersionUID, JVM will do it for you automatically, based on various aspects of your Serializable class, Nice article regarding this http://www.mkyong.com/java-best-practices/understand-the-serialversionuid/