Saturday, 12 March 2016

Creating Entity classes for tables which do not have any primary key in Hibernate

Create a class with composite keys

@Embeddable
public class ClassificationPK implements Serializable {
    @Column(name="EMPLOYEE_NAME")
private String username;
@Column(name="EMPLOYEE_PHONE_NUMBER")
private String userDet;
}


@Entity
@Table(name="EMPLOYEE", schema="employee_detail")
@NamedQuery(name="Employee.findAll", query="SELECT i FROM Employee i")
public class Employee implements Serializable {
private static final long serialVersionUID = 1L;

@Column(name="EMPLOYEE_NAME" , insertable=false, updateble=false)
private String userName;

@Column(name="EMPLOYEE_DETAILS")
private String userDet;

@Column(name="EMPLOYEE_PHONE_NUMBER" , insertable=false, updateble=false)
private String userDet;

}

How to resolve Error "Error occurred during initialization of VM" in Eclipse Kepler


If you get the below error in Eclipse Kepler while starting JBOSS server or any other server

Error occurred during initialization of VM
Could not reserve enough space for 1048576KB object heap
Picked up JAVA_TOOL_OPTIONS: -Djava.vendor="Sun Microsystems Inc."
Java HotSpot(TM) Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0

Then try to modify as like below by double clicking on the Jboss server from Servers tab in Eclipse and then click on "Open launch configuration" . Edit the vm arguments  under the Arguments
if  Xms & Xmx  value is set to 1024 lower them to 512
-server -Xms512m -Xmx512m -XX:MaxPermSize=256m

Wednesday, 17 February 2016

How to resolve the error "java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: TravelEntity is not mapped" in hibernate

If you encounter any such error

java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: TravelEntity is not mapped [ from TravelEntity]
org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1374)
org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1310)
org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:294)

Add an entry in persistence.xml of the particular entity class  as like below under the persistenceunit tag
<class>com.data.TravelEntity</class>

Ex:
<persistence-unit name="travelPU" transaction-type="JTA">
<class>com.data.TravelEntity</class>

Ho to resolve error such as "java.lang.IncompatibleClassChangeError: Implementing class" in while running pom through Eclipse IDE

If you see any such error as like below


java.lang.IncompatibleClassChangeError: Implementing class

Invocation of init method failed; nested exception is java.lang.IncompatibleClassChangeError: Implementing class


1) Try to do maven clean by right clicking on the pom.xml in the project.
2) Right click on all the projects that has dependencies choose  Maven--> Update Project... --> then select check box Force Update of Snapshots/Releases run maven install and do update
3) Then run maven install by right clicking on the pom.xml in the project.


Ho to resolve "org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalArgumentException:..."

If you find any such error as like below

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalArgumentException: No converter found for return value of type: class com.xxx.xxx
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:981)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:860)
javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:845)


then please add the below lines of code in the project specific applicationcontext.xml, the primary reason may be class may not be loaded

<context:component-scan base-package="com.xxx.xxx" />
<mvc:annotation-driven />

How to resolve one of the Spring+Hibernate JTA Transaction error

If you are using jboss server for deployment and find the error as below in console

java.lang.NullPointerException org.hibernate.engine.transaction.internal.jta.JtaStatusHelper.getStatus(JtaStatusHelper.java:73).............................


then try to add the below property in persistence.xml

<property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform" />

How to resolve error ClassNotFoundException in Hibernate


If you find the  error as follows then try to have a look at the persistence.xml to check whether it has any classes which is not present in the project.Remove the classnames from the persistence.xml

Caused by: javax.persistence.PersistenceException: [PersistenceUnit: xxxPU] class or package not found
at org.hibernate.ejb.Ejb3Configuration.addNamedAnnotatedClasses(Ejb3Configuration.java:1431)
at org.hibernate.ejb.Ejb3Configuration.addClassesToSessionFactory(Ejb3Configuration.java:1214)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:1058)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:703)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:75)
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.createContainerEntityManagerFactory(PersistenceUnitServiceImpl.java:200)
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.access$600(PersistenceUnitServiceImpl.java:57)
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:99)
... 4 more

Caused by: java.lang.ClassNotFoundException: xxxxx from [Module "org.hibernate:main" from local module loader @9e89d68 (finder: local module finder @3b192d32 (roots: