i using spring 3.1 , eclipselink 2 tomcat, reason data not persisting.. table being generated though.
dispatcher-servlet.xml
<?xml version="1.0" encoding="utf-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <context:component-scan base-package="com.myapp.user.controllers" /> <mvc:annotation-driven /> <bean class="org.springframework.web.servlet.mvc.support.controllerclassnamehandlermapping"/> <bean id="viewresolver" class="org.springframework.web.servlet.view.internalresourceviewresolver" p:prefix="/web-inf/jsp/" p:suffix=".jsp" /> </beans>
applicationcontext.xml
<?xml version="1.0" encoding="utf-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <aop:aspectj-autoproxy /> <context:load-time-weaver aspectj-weaving="on"/> <bean class="org.springframework.dao.annotation.persistenceexceptiontranslationpostprocessor" /> <bean id="loadtimeweaver" class="org.springframework.instrument.classloading.instrumentationloadtimeweaver" /> <bean id="jpavendoradapter" class="org.springframework.orm.jpa.vendor.eclipselinkjpavendoradapter"> <property name="database" value="mysql"/> <property name="showsql" value="true"/> <property name="generateddl" value="false"/> <property name="databaseplatform" value="org.eclipse.persistence.platform.database.mysqlplatform"/> </bean> <bean id="entitymanagerfactory" class="org.springframework.orm.jpa.localcontainerentitymanagerfactorybean" p:persistenceunitname="myapppu" p:persistencexmllocation="classpath*:meta-inf/persistence.xml" p:jpavendoradapter-ref="jpavendoradapter" p:loadtimeweaver-ref="loadtimeweaver" p:datasource-ref="datasource" /> <bean id="txmanager" class="org.springframework.orm.jpa.jpatransactionmanager" p:entitymanagerfactory-ref="entitymanagerfactory" p:datasource-ref="datasource" /> <bean id="datasource" class="org.springframework.jdbc.datasource.drivermanagerdatasource"> <property name="driverclassname" value="com.mysql.jdbc.driver"/> <property name="url" value="jdbc:mysql://localhost:3306/qpdb?zerodatetimebehavior=converttonull"/> <property name="username" value="root"/> <property name="password" value=""/> </bean> <tx:annotation-driven transaction-manager="txmanager" /> </beans>
persistence.xml
<?xml version="1.0" encoding="utf-8"?> <persistence version="2.0" 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_2_0.xsd"> <persistence-unit name="myapppu" transaction-type="resource_local"> <provider>org.eclipse.persistence.jpa.persistenceprovider</provider> <class>com.myapp.entities.genericuser</class> <properties> <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/qpdb?zerodatetimebehavior=converttonull"/> <property name="javax.persistence.jdbc.password" value=""/> <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.driver"/> <property name="javax.persistence.jdbc.user" value="root"/> <!--<property name="eclipselink.weaving" value="static"/>--> </properties> </persistence-unit> </persistence>
welcomecontroller.java
package com.myapp.user.controllers; import com.myapp.entities.genericuser; import java.math.biginteger; import java.util.map; import javax.persistence.entitymanager; import javax.persistence.persistencecontext; import org.springframework.stereotype.controller; import org.springframework.transaction.annotation.propagation; import org.springframework.transaction.annotation.transactional; import org.springframework.web.bind.annotation.requestmapping; @transactional(propagation=propagation.supports) @controller public class welcomecontroller { @persistencecontext private entitymanager entitymanager; public welcomecontroller() { } @requestmapping({"/"}) public string showpublicpage(map<string, object> model) { genericuser gu = new genericuser(); adduser(gu); return "welcome"; } @transactional(propagation= propagation.required,readonly=false) public void adduser(genericuser gu) { gu.setuserid(biginteger.one); gu.setemail("asdfadf"); entitymanager.persist(gu); } }
genericuser.java
package com.myapp.entities; import java.io.serializable; import java.math.biginteger; import java.util.date; import javax.persistence.column; import javax.persistence.entity; import javax.persistence.generatedvalue; import javax.persistence.generationtype; import javax.persistence.id; import javax.persistence.table; import javax.persistence.temporal; @entity @table(name="generic_user") public class genericuser implements serializable { private static final long serialversionuid = 1l; @id @generatedvalue(strategy = generationtype.identity) @column(name = "user_id") private biginteger userid; @column(name = "username") private string username; @column(name = "email") private string email; @column(name = "password") private string password; public biginteger getuserid() { return userid; } public void setuserid(biginteger id) { this.userid = id; } public string getusername() { return username; } public void setusername(string username) { this.username = username; } public string getemail() { return email; } public void setemail(string email) { this.email = email; } public string getpassword() { return password; } public void setpassword(string password) { this.password = password; } @override public int hashcode() { int hash = 0; hash += (userid != null ? userid.hashcode() : 0); return hash; } @override public boolean equals(object object) { // todo: warning - method won't work in case id fields not set if (!(object instanceof genericuser)) { return false; } genericuser other = (genericuser) object; if ((this.userid == null && other.userid != null) || (this.userid != null && !this.userid.equals(other.userid))) { return false; } return true; } @override public string tostring() { return "com.myapp.entities.genericuser[ id=" + userid + " ]"; } }
i starting tomcat -javaagent:path/to/spring-agent-2.5.6.sec03.jar
tomcat log
jul 11, 2013 9:30:36 pm org.apache.catalina.core.applicationcontext log
info: destroying spring frameworkservlet 'dispatcher'
jul 11, 2013 9:30:36 pm org.apache.catalina.core.applicationcontext log
info: closing spring root webapplicationcontext
jul 11, 2013 9:33:13 pm org.apache.catalina.core.applicationcontext log
info: no spring webapplicationinitializer types detected on classpath
jul 11, 2013 9:33:13 pm org.apache.catalina.core.applicationcontext log
info: initializing spring root webapplicationcontext
jul 11, 2013 9:33:13 pm org.apache.catalina.core.standardcontext listenerstart
severe: exception sending context initialized event listener instance of class org.springframework.web.context.contextloaderlistener
org.springframework.beans.factory.xml.xmlbeandefinitionstoreexception: line 52 in xml document servletcontext resource [/web-inf/applicationcontext.xml] invalid; nested exception org.xml.sax.saxparseexception; linenumber: 52; columnnumber: 6; processing instruction target matching "[xx][mm][ll]" not allowed.
at org.springframework.beans.factory.xml.xmlbeandefinitionreader.doloadbeandefinitions(xmlbeandefinitionreader.java:396)
at org.springframework.beans.factory.xml.xmlbeandefinitionreader.loadbeandefinitions(xmlbeandefinitionreader.java:334)
at org.springframework.beans.factory.xml.xmlbeandefinitionreader.loadbeandefinitions(xmlbeandefinitionreader.java:302)
at org.springframework.beans.factory.support.abstractbeandefinitionreader.loadbeandefinitions(abstractbeandefinitionreader.java:174)
at org.springframework.beans.factory.support.abstractbeandefinitionreader.loadbeandefinitions(abstractbeandefinitionreader.java:209)
at org.springframework.beans.factory.support.abstractbeandefinitionreader.loadbeandefinitions(abstractbeandefinitionreader.java:180)
at org.springframework.web.context.support.xmlwebapplicationcontext.loadbeandefinitions(xmlwebapplicationcontext.java:125)
at org.springframework.web.context.support.xmlwebapplicationcontext.loadbeandefinitions(xmlwebapplicationcontext.java:94)
at org.springframework.context.support.abstractrefreshableapplicationcontext.refreshbeanfactory(abstractrefreshableapplicationcontext.java:131)
at org.springframework.context.support.abstractapplicationcontext.obtainfreshbeanfactory(abstractapplicationcontext.java:522)
at org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:436)
at org.springframework.web.context.contextloader.configureandrefreshwebapplicationcontext(contextloader.java:385)
at org.springframework.web.context.contextloader.initwebapplicationcontext(contextloader.java:284)
at org.springframework.web.context.contextloaderlistener.contextinitialized(contextloaderlistener.java:111)
at org.apache.catalina.core.standardcontext.listenerstart(standardcontext.java:4779)
at org.apache.catalina.core.standardcontext.startinternal(standardcontext.java:5273)
at org.apache.catalina.util.lifecyclebase.start(lifecyclebase.java:150)
at org.apache.catalina.core.containerbase.addchildinternal(containerbase.java:895)
at org.apache.catalina.core.containerbase.addchild(containerbase.java:871)
at org.apache.catalina.core.standardhost.addchild(standardhost.java:615)
at org.apache.catalina.startup.hostconfig.deploydescriptor(hostconfig.java:649)
at org.apache.catalina.startup.hostconfig$deploydescriptor.run(hostconfig.java:1585)
at java.util.concurrent.executors$runnableadapter.call(executors.java:471)
at java.util.concurrent.futuretask$sync.innerrun(futuretask.java:334)
at java.util.concurrent.futuretask.run(futuretask.java:166)
at java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1110)
at java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:603)
at java.lang.thread.run(thread.java:722)
caused by: org.xml.sax.saxparseexception; linenumber: 52; columnnumber: 6; processing instruction target matching "[xx][mm][ll]" not allowed.
at com.sun.org.apache.xerces.internal.util.errorhandlerwrapper.createsaxparseexception(errorhandlerwrapper.java:198)
at com.sun.org.apache.xerces.internal.util.errorhandlerwrapper.fatalerror(errorhandlerwrapper.java:177)
at com.sun.org.apache.xerces.internal.impl.xmlerrorreporter.reporterror(xmlerrorreporter.java:441)
at com.sun.org.apache.xerces.internal.impl.xmlerrorreporter.reporterror(xmlerrorreporter.java:368)
at com.sun.org.apache.xerces.internal.impl.xmlscanner.reportfatalerror(xmlscanner.java:1388)
at com.sun.org.apache.xerces.internal.impl.xmlscanner.scanpidata(xmlscanner.java:675)
at com.sun.org.apache.xerces.internal.impl.xmldocumentfragmentscannerimpl.scanpidata(xmldocumentfragmentscannerimpl.java:980)
at com.sun.org.apache.xerces.internal.impl.xmlscanner.scanpi(xmlscanner.java:643)
at com.sun.org.apache.xerces.internal.impl.xmldocumentscannerimpl$prologdriver.next(xmldocumentscannerimpl.java:913)
at com.sun.org.apache.xerces.internal.impl.xmldocumentscannerimpl.next(xmldocumentscannerimpl.java:607)
at com.sun.org.apache.xerces.internal.impl.xmlnsdocumentscannerimpl.next(xmlnsdocumentscannerimpl.java:116)
at com.sun.org.apache.xerces.internal.impl.xmldocumentfragmentscannerimpl.scandocument(xmldocumentfragmentscannerimpl.java:489)
at com.sun.org.apache.xerces.internal.parsers.xml11configuration.parse(xml11configuration.java:835)
at com.sun.org.apache.xerces.internal.parsers.xml11configuration.parse(xml11configuration.java:764)
at com.sun.org.apache.xerces.internal.parsers.xmlparser.parse(xmlparser.java:123)
at com.sun.org.apache.xerces.internal.parsers.domparser.parse(domparser.java:237)
at com.sun.org.apache.xerces.internal.jaxp.documentbuilderimpl.parse(documentbuilderimpl.java:300)
at org.springframework.beans.factory.xml.defaultdocumentloader.loaddocument(defaultdocumentloader.java:75)
at org.springframework.beans.factory.xml.xmlbeandefinitionreader.doloadbeandefinitions(xmlbeandefinitionreader.java:388)
... 27 more
jul 11, 2013 9:33:13 pm org.apache.catalina.core.applicationcontext log
info: closing spring root webapplicationcontext
jul 11, 2013 9:33:13 pm org.apache.catalina.core.standardcontext listenerstop
severe: exception sending context destroyed event listener instance of class org.springframework.web.context.contextloaderlistener
java.lang.illegalstateexception: beanfactory not initialized or closed - call 'refresh' before accessing beans via applicationcontext
at org.springframework.context.support.abstractrefreshableapplicationcontext.getbeanfactory(abstractrefreshableapplicationcontext.java:172)
at org.springframework.context.support.abstractapplicationcontext.destroybeans(abstractapplicationcontext.java:1066)
at org.springframework.context.support.abstractapplicationcontext.doclose(abstractapplicationcontext.java:1040)
at org.springframework.context.support.abstractapplicationcontext.close(abstractapplicationcontext.java:988)
at org.springframework.web.context.contextloader.closewebapplicationcontext(contextloader.java:556)
at org.springframework.web.context.contextloaderlistener.contextdestroyed(contextloaderlistener.java:142)
at org.apache.catalina.core.standardcontext.listenerstop(standardcontext.java:4819)
at org.apache.catalina.core.standardcontext.stopinternal(standardcontext.java:5466)
at org.apache.catalina.util.lifecyclebase.stop(lifecyclebase.java:232)
at org.apache.catalina.util.lifecyclebase.start(lifecyclebase.java:160)
at org.apache.catalina.core.containerbase.addchildinternal(containerbase.java:895)
at org.apache.catalina.core.containerbase.addchild(containerbase.java:871)
at org.apache.catalina.core.standardhost.addchild(standardhost.java:615)
at org.apache.catalina.startup.hostconfig.deploydescriptor(hostconfig.java:649)
at org.apache.catalina.startup.hostconfig$deploydescriptor.run(hostconfig.java:1585)
at java.util.concurrent.executors$runnableadapter.call(executors.java:471)
at java.util.concurrent.futuretask$sync.innerrun(futuretask.java:334)
at java.util.concurrent.futuretask.run(futuretask.java:166)
at java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1110)
at java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:603)
at java.lang.thread.run(thread.java:722)
jul 11, 2013 9:33:15 pm org.apache.catalina.core.applicationcontext log
info: no spring webapplicationinitializer types detected on classpath
jul 11, 2013 9:33:15 pm org.apache.catalina.core.applicationcontext log
info: initializing spring root webapplicationcontext
jul 11, 2013 9:33:18 pm org.apache.catalina.core.applicationcontext log
info: initializing spring frameworkservlet 'dispatcher'
jul 11, 2013 9:34:32 pm org.apache.catalina.core.applicationcontext log
info: destroying spring frameworkservlet 'dispatcher'
jul 11, 2013 9:34:32 pm org.apache.catalina.core.applicationcontext log
info: closing spring root webapplicationcontext
jul 11, 2013 9:34:34 pm org.apache.catalina.core.applicationcontext log
info: no spring webapplicationinitializer types detected on classpath
jul 11, 2013 9:34:34 pm org.apache.catalina.core.applicationcontext log
info: initializing spring root webapplicationcontext
jul 11, 2013 9:34:37 pm org.apache.catalina.core.applicationcontext log
info: initializing spring frameworkservlet 'dispatcher'
the application runs , opens 'welcome' view data (genericuser gu) not persist...
probably p:persistencexmllocation="classpath*:meta-inf/persistence.xml"
wrong.. try put xml on web-inf/ folder , link as: persistencexmllocation="myxml.xml"
Comments
Post a Comment