Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Virgo » Virgo 3.5+ hibernate 4 + spring 3.1.1 unknown entity problem
Virgo 3.5+ hibernate 4 + spring 3.1.1 unknown entity problem [message #813633] Mon, 05 March 2012 14:29 Go to next message
Jay Huang is currently offline Jay HuangFriend
Messages: 20
Registered: February 2012
Junior Member
Hi all,

I am using VTS 3.5.0.M2 + Spring 3.1.1.release + hibernate 4.1.0.Final, when i start the web bundle that contains the jpa annotated persistent entities, it throws this error (import the right Entity annotation : javax.persistence.Entity):

org.hibernate.MappingException: Unknown entity: web.virgo.Person
	org.hibernate.internal.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:1172)
	org.hibernate.internal.SessionImpl.getEntityPersister(SessionImpl.java:1316)
	org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:117)
	org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:204)
	org.hibernate.event.internal.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:55)
	org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:189)
	org.hibernate.event.internal.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:49)
	org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:90)
	org.hibernate.internal.SessionImpl.fireSave(SessionImpl.java:670)
	org.hibernate.internal.SessionImpl.save(SessionImpl.java:662)
	org.hibernate.internal.SessionImpl.save(SessionImpl.java:658)
	web.virgo.PersonDao.save(PersonDao.java:23)
	web.virgo.PersonDao$$FastClassByCGLIB$$d93c55c.invoke(<generated>)
	net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191)
	org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:689)
	org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
	org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
	org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
	org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:622)
	web.virgo.PersonDao$$EnhancerByCGLIB$$e011172d.save(<generated>)
	web.virgo.HelloServlet.showWidgetTestView(HelloServlet.java:22)
	sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	java.lang.reflect.Method.invoke(Unknown Source)
	org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
	org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:436)
	org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:424)
	org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
	org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
	org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:735)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:848)



Here is my MANIFET.MF :

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Web
Bundle-SymbolicName: com.osgi.web
Bundle-Version: 1.0.0.qualifier
Web-ContextPath: virgo
Import-Package: com.mysql.jdbc;version="[5.1.6,5.1.6]",
 javax.annotation;version="[1.0.0,1.0.0]",
 javax.servlet;version="[3.0.0,3.0.0]",
 javax.servlet.http;version="[3.0.0,3.0.0]",
 javax.sql,
 org.aopalliance.aop;version="[1.0.0,1.0.0]",
 org.aopalliance.intercept;version="[1.0.0,1.0.0]"
Import-Bundle: org.springframework.orm;version="[3.1.1.RELEASE,3.1.1.RELEASE]",
 org.springframework.core;version="[3.1.1.RELEASE,3.1.1.RELEASE]",
 org.springframework.transaction;version="[3.1.1.RELEASE,3.1.1.RELEASE]",
 org.springframework.aop;version="[3.1.1.RELEASE,3.1.1.RELEASE]",
 org.springframework.asm;version="[3.1.1.RELEASE,3.1.1.RELEASE]",
 org.springframework.aspects;version="[3.1.1.RELEASE,3.1.1.RELEASE]",
 org.springframework.beans;version="[3.1.1.RELEASE,3.1.1.RELEASE]",
 org.springframework.context;version="[3.1.1.RELEASE,3.1.1.RELEASE]",
 org.springframework.context.support;version="[3.1.1.RELEASE,3.1.1.RELEASE]",
 org.springframework.expression;version="[3.1.1.RELEASE,3.1.1.RELEASE]",
 org.springframework.jdbc;version="[3.1.1.RELEASE,3.1.1.RELEASE]",
 org.springframework.web;version="[3.1.1.RELEASE,3.1.1.RELEASE]",
 org.springframework.web.portlet;version="[3.1.1.RELEASE,3.1.1.RELEASE]",
 org.springframework.web.servlet;version="[3.1.1.RELEASE,3.1.1.RELEASE]",
 com.springsource.org.apache.commons.dbcp;version="[1.2.2.osgi,1.2.2.osgi]",
 com.springsource.org.apache.commons.pool;version="[1.5.3,1.5.3]",
 com.springsource.net.sf.cglib;version="[2.2.0,2.2.0]",
 com.springsource.org.hibernate.annotations.common;version="[4.1.0.Final,4.1.0.Final]",
 com.springsource.org.hibernate.core;version="[4.1.0.Final,4.1.0.Final]";import-scope:=application,
 com.springsource.org.hibernate.validator;version="[4.2.0.Final,4.2.0.Final]",
 org.springframework.jms;version="[3.1.1.RELEASE,3.1.1.RELEASE]",
 org.springframework.osgi.core;version="[1.2.1,1.2.1]",
 org.springframework.osgi.extender;version="[1.2.1,1.2.1]",
 org.springframework.osgi.io;version="[1.2.1,1.2.1]",
 org.springframework.oxm;version="[3.1.1.RELEASE,3.1.1.RELEASE]"
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Require-Bundle:  org.hibernate.bundle.hibernate-jpa-bundle,com.springsource.javax.persistence
Export-Package: web.virgo;uses:="org.springframework.ui,org.springframework.orm.hibernate4"




the "org.hibernate.bundle.hibernate-jpa-bundle" is a osgi-fied hibernate-jpa-api-2.0.

and the spring config file :

	<!-- configure annotated Bean -->
	<context:annotation-config />
	<!-- Auto Component Scan -->
	<context:component-scan base-package="web.virgo" />

	<tx:annotation-driven />

	<!-- <context:property-placeholder location="classpath:config.properties" 
		/> -->

	<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
		destroy-method="close">
		<property name="driverClassName" value="com.mysql.jdbc.Driver" />
		<property name="url" value="jdbc:mysql://localhost:3306/virgo" />
		<property name="username" value="jayh" />
		<property name="password" value="undead2009" />
	</bean>

	<bean id="formSessionFactoryBean"
		class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
		<property name="dataSource" ref="dataSource" />
		<property name="hibernateProperties">
			<props>
				<prop key="hibernate.hbm2ddl.auto">update</prop>
				<prop key="hibernate.show_sql">true</prop>
				<prop key="hibernate.format_sql">true</prop>
				<prop key="hibernate.dialet">org.hibernate.dialect.MySQLDialect</prop>
				<prop key="shared-cache-mode">NONE</prop>
			</props>
		</property>
		<property name="packagesToScan">
			<array>
				<value>web.virgo</value>
			</array>
		</property>
		<property name="annotatedPackages">
			<array>
				<value>web.virgo</value>
			</array>
		</property>
	</bean>


	<bean id="transactionManager"
		class="org.springframework.orm.hibernate4.HibernateTransactionManager">
		<constructor-arg ref="formSessionFactoryBean" />
	</bean>

	<bean id="transactionTemplate"
		class="org.springframework.transaction.support.TransactionTemplate">
		<property name="transactionManager" ref="transactionManager" />
	</bean>

	<bean
		class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
	<bean
		class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />





	<!-- Forwards requests to the "/" resource to the "welcome" view -->
	<mvc:view-controller path="/" view-name="layout" />

	<bean id="viewResolver"
		class="org.springframework.web.servlet.view.UrlBasedViewResolver">
		<property name="viewClass"
			value="org.springframework.web.servlet.view.JstlView" />
		<property name="prefix" value="/WEB-INF/views/" />
		<property name="suffix" value=".jsp" />
	</bean>

</beans>


and the entity class :

package web.virgo;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name="person")
public class Person {

	@Id
	@GeneratedValue
	private long id;

	private String name;

	public String getName() {
		return name;
	}

	public void setName(final String name) {
		this.name = name;
	}

}


I guess the problem is the osgi class loader thing when finding the annotated entities while building the session factory. But because the session factory is created by spring, i cannot do anything about the classloader.

Is there anything i missed or i am doing something wrong?
Thank you.

Jay

[Updated on: Mon, 05 March 2012 14:31]

Report message to a moderator

Re: Virgo 3.5+ hibernate 4 + spring 3.1.1 unknown entity problem [message #813719 is a reply to message #813633] Mon, 05 March 2012 16:35 Go to previous messageGo to next message
Chris Frost is currently offline Chris FrostFriend
Messages: 230
Registered: January 2010
Location: Southampton, England
Senior Member

Hi,

We don't support Spring 3.1.x yet as it requires a newer version of AspectJ and some other changes. The work as been done and will be released in due course but until then you should stay on Spring 3.0.x. You can see the changes in the git repos for the Virgo Kernel and Web layers if you wanted to try them out yourself. I suspect they would fix your problems but until we release them there isn't much we can do.

Chris.


------------------------------------------------
Chris Frost, Twitter @cgfrost
Springsource, a divison of VMware.
Re: Virgo 3.5+ hibernate 4 + spring 3.1.1 unknown entity problem [message #1314029 is a reply to message #813719] Fri, 25 April 2014 06:01 Go to previous message
Rajiv Croos is currently offline Rajiv CroosFriend
Messages: 2
Registered: April 2014
Junior Member
Hi Jay,

Did you overcome the situation. what did you do. cause im also trying to implement a modular java application using spring and hibernate and couldn't resolve the dependencies after adding the hibernate features to the bundle. if you can share you working sample that would be great. And i would like to now how did you add snap bundle dependencies in Virgo.

Thanks a lot.

Rajiv.
Previous Topic:Moving from 3.5.0 to 3.6.2.RELEASE results in "not visible from classloader"
Next Topic:Virgo project about to be deleted!
Goto Forum:
  


Current Time: Thu Mar 28 12:32:35 GMT 2024

Powered by FUDForum. Page generated in 0.03205 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top