0

朋友們你好,如果有人能幫我解決這個問題,那將會很棒。 我正試圖在谷歌應用程序引擎上構建一個Web應用程序。我無法使用jpa將數據寫入數據庫,並且沒有例外。我嘗試BT它給了我的異常使用沖洗,如下所示:GAE + JPA + Spring - 無法將數據插入數據庫(Mysql)

javax.persistence.TransactionRequiredException: no transaction is in progress 
    at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:301) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:606) 
    at com.google.appengine.tools.development.agent.runtime.Runtime.invoke(Runtime.java:115) 
    at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:365) 
    at com.sun.proxy.$Proxy31.flush(Unknown Source) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:606) 
    at com.google.appengine.tools.development.agent.runtime.Runtime.invoke(Runtime.java:115) 
    at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:240) 
    at com.sun.proxy.$Proxy31.flush(Unknown Source) 
    at com.bullbeardevice.dao.impl.BaseDAOImpl.save(BaseDAOImpl.java:52) 
    at com.bullbeardevice.service.impl.LoginServiceImpl.authenthicateUserLogin(LoginServiceImpl.java:70) 
    at com.bullbeardevice.controller.common.LoginController.authenticateUserLogin(LoginController.java:35) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:606) 
    at com.google.appengine.tools.development.agent.runtime.Runtime.invoke(Runtime.java:115) 
    at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219) 
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132) 
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:100) 
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:604) 
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:565) 
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80) 
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923) 
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852) 
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882) 
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:637) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) 
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511) 
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166) 
    at org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:147) 
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) 
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) 
    at com.google.appengine.api.socket.dev.DevSocketFilter.doFilter(DevSocketFilter.java:74) 
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) 
    at com.google.appengine.tools.development.ResponseRewriterFilter.doFilter(ResponseRewriterFilter.java:127) 
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) 
    at com.google.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:34) 
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) 
    at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:63) 
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) 
    at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43) 
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) 
    at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:125) 
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) 
    at com.google.appengine.tools.development.DevAppServerModulesFilter.doDirectRequest(DevAppServerModulesFilter.java:366) 
    at com.google.appengine.tools.development.DevAppServerModulesFilter.doDirectModuleRequest(DevAppServerModulesFilter.java:349) 
    at com.google.appengine.tools.development.DevAppServerModulesFilter.doFilter(DevAppServerModulesFilter.java:116) 
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) 
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388) 
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216) 
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182) 
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765) 
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418) 
    at com.google.appengine.tools.development.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:98) 
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152) 
    at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:490) 
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152) 
    at org.mortbay.jetty.Server.handle(Server.java:326) 
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542) 
    at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:938) 
    at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:755) 
    at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218) 
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404) 
    at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409) 
    at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582) 
2014-07-23 17:27:39,731 [[email protected]] DEBUG (LoginController.java:46) – End of method loginUser of class LoginController 

我將不勝感激,如果有人能幫助我與此有關。

+0

這並不能提供很多東西。你能分享一些更詳細的信息,比如來自LoginServiceImpl.authenthicateUserLogin和BaseDAOImpl.save的片段(包括任何註釋),S​​pring JPA配置等。 – manish

+0

您好Manish感謝您的回覆我的問題已解決bt我正在面臨另一個提取記錄org.hibernate.exception.SQLGrammarException:'字段列表'中的未知列'userlogind0_.jdoDetachedState'。我沒有任何這樣的領域在查詢和我的表或實體。我相信這是用來跟蹤對象的狀態,請告訴我如何處理這個問題。 – Archit

回答

0

谷歌應用程序引擎uses the DataNucleus Access Platform作爲JPA 1.0的實現。默認情況下,DataNucleus JPA提供程序希望註釋爲@Entity的每個類具有jdoDetachedState屬性,映射到數據庫表中的適當列。

您有以下選擇:

  1. 添加一個名爲jdoDetachedState到實體財產,並添加相應的列於表爲好。
  2. 按照in this Google Forums post所述的步驟,通過DataNucleus關閉分離模式。
  3. in this DataNucleus JIRA所述的每個實體添加一個transient屬性jdoDetachedState
+0

如果必須使用第一個選項,那麼數據庫中的jdoDetachedState的數據類型是什麼? – Archit

+0

您是否確實想要[在分離模式下使用對象](https://db.apache.org/jdo/ attach_detach.html)?如果您擁有一個乾淨的架構,只有業務邏輯加載模型對象並對其進行工作,則DataNucleus不需要可拆卸對象,您應該使用上面列出的選項#2。如果你決定選擇#1,Java數據類型將是Object [],數據庫類型應該是BLOB。但是,該屬性僅在運行時由DataNucleus使用,並且永遠不會保留,因此您應該儘量避免使用選項#1。 – manish

+0

感謝Manish爲您快速響應。我已經使用選項2 bt的問題,該解決方案是隨機工作。有時它有時會起作用,但它會產生相同的錯誤 – Archit

0

我的實體類看起來是這樣的:

package com.bullbeardevice.model; 

import java.io.Serializable; 
import java.util.Date; 
import java.util.List; 

import javax.persistence.Column; 
import javax.persistence.Entity; 
import javax.persistence.GeneratedValue; 
import javax.persistence.GenerationType; 
import javax.persistence.Id; 
import javax.persistence.JoinColumn; 
import javax.persistence.ManyToOne; 
import javax.persistence.NamedQuery; 
import javax.persistence.OneToMany; 
import javax.persistence.Table; 
import javax.persistence.Temporal; 
import javax.persistence.TemporalType; 

/** 
* The persistent class for the user_registration database table. 
* 
*/ 
@Entity 
@Table(name = "user_registration") 
@NamedQuery(name = "UserRegistration.findAll", query = "SELECT u FROM UserRegistration u") 
public class UserRegistration implements Serializable { 
    private static final long serialVersionUID = 1L; 

    @Id 
    @GeneratedValue(strategy = GenerationType.AUTO) 
    @Column(name = "user_Registration_Id") 
    private String userRegistrationId; 

    @Column(name = "account_Status") 
    private int accountStatus; 

    @Column(name = "created_By") 
    private String createdBy; 

    @Column(name = "created_On") 
    @Temporal(TemporalType.TIMESTAMP) 
    private Date createdOn; 

    @Column(name = "email_Address") 
    private String emailAddress; 

    @Column(name = "expiry_Date") 
    @Temporal(TemporalType.TIMESTAMP) 
    private Date expiryDate; 

    @ManyToOne 
    @JoinColumn(name = "Group_Master_Id") 
    private GroupMaster groupMaster; 

    @Column(name = "modified_By") 
    private String modifiedBy; 

    @Temporal(TemporalType.TIMESTAMP) 
    @Column(name = "modified_On") 
    private Date modifiedOn; 

    @Column(name = "user_password") 
    private String password; 

    @Column(name = "permissions") 
    private int permissions; 

    // bi-directional many-to-one association to Chat 
    @OneToMany(mappedBy = "userRegistration") 
    private List<Chat> chats; 

    // bi-directional many-to-one association to Coupon 
    @OneToMany(mappedBy = "userRegistration") 
    private List<Coupon> coupons; 

    // bi-directional many-to-one association to DeviceDetail 
    @OneToMany(mappedBy = "userRegistration") 
    private List<DeviceDetail> deviceDetails; 

    // bi-directional many-to-one association to Portfolio 
    @OneToMany(mappedBy = "userRegistration") 
    private List<Portfolio> portfolios; 

    // bi-directional many-to-one association to UserDetail 
    @OneToMany(mappedBy = "userRegistration") 
    private List<UserDetail> userDetails; 

    // bi-directional many-to-one association to UserLoginDetail 
    @OneToMany(mappedBy = "userRegistration") 
    private List<UserLoginDetail> userLoginDetails; 

    // bi-directional many-to-one association to UserRoleMaster 
    @ManyToOne 
    @JoinColumn(name = "User_Role_Master_Id") 
    private UserRoleMaster userRoleMaster; 

    // bi-directional many-to-one association to Watch 
    @OneToMany(mappedBy = "userRegistration") 
    private List<Watch> watches; 

    public UserRegistration() { 
    } 

    /** 
    * @return the userRegistrationId 
    */ 
    public String getUserRegistrationId() { 
     return userRegistrationId; 
    } 

    /** 
    * @param userRegistrationId 
    *   the userRegistrationId to set 
    */ 
    public void setUserRegistrationId(String userRegistrationId) { 
     this.userRegistrationId = userRegistrationId; 
    } 

    /** 
    * @return the accountStatus 
    */ 
    public int getAccountStatus() { 
     return accountStatus; 
    } 

    /** 
    * @param accountStatus 
    *   the accountStatus to set 
    */ 
    public void setAccountStatus(int accountStatus) { 
     this.accountStatus = accountStatus; 
    } 

    /** 
    * @return the createdBy 
    */ 
    public String getCreatedBy() { 
     return createdBy; 
    } 

    /** 
    * @param createdBy 
    *   the createdBy to set 
    */ 
    public void setCreatedBy(String createdBy) { 
     this.createdBy = createdBy; 
    } 

    /** 
    * @return the createdOn 
    */ 
    public Date getCreatedOn() { 
     return createdOn; 
    } 

    /** 
    * @param createdOn 
    *   the createdOn to set 
    */ 
    public void setCreatedOn(Date createdOn) { 
     this.createdOn = createdOn; 
    } 

    /** 
    * @return the emailAddress 
    */ 
    public String getEmailAddress() { 
     return emailAddress; 
    } 

    /** 
    * @param emailAddress 
    *   the emailAddress to set 
    */ 
    public void setEmailAddress(String emailAddress) { 
     this.emailAddress = emailAddress; 
    } 

    /** 
    * @return the expiryDate 
    */ 
    public Date getExpiryDate() { 
     return expiryDate; 
    } 

    /** 
    * @param expiryDate 
    *   the expiryDate to set 
    */ 
    public void setExpiryDate(Date expiryDate) { 
     this.expiryDate = expiryDate; 
    } 

    /** 
    * @return the groupMaster 
    */ 
    public GroupMaster getGroupMaster() { 
     return groupMaster; 
    } 

    /** 
    * @param groupMaster 
    *   the groupMaster to set 
    */ 
    public void setGroupMaster(GroupMaster groupMaster) { 
     this.groupMaster = groupMaster; 
    } 

    /** 
    * @return the modifiedBy 
    */ 
    public String getModifiedBy() { 
     return modifiedBy; 
    } 

    /** 
    * @param modifiedBy 
    *   the modifiedBy to set 
    */ 
    public void setModifiedBy(String modifiedBy) { 
     this.modifiedBy = modifiedBy; 
    } 

    /** 
    * @return the modifiedOn 
    */ 
    public Date getModifiedOn() { 
     return modifiedOn; 
    } 

    /** 
    * @param modifiedOn 
    *   the modifiedOn to set 
    */ 
    public void setModifiedOn(Date modifiedOn) { 
     this.modifiedOn = modifiedOn; 
    } 

    /** 
    * @return the password 
    */ 
    public String getPassword() { 
     return password; 
    } 

    /** 
    * @param password 
    *   the password to set 
    */ 
    public void setPassword(String password) { 
     this.password = password; 
    } 

    /** 
    * @return the permissions 
    */ 
    public int getPermissions() { 
     return permissions; 
    } 

    /** 
    * @param permissions 
    *   the permissions to set 
    */ 
    public void setPermissions(int permissions) { 
     this.permissions = permissions; 
    } 

    /** 
    * @return the chats 
    */ 
    public List<Chat> getChats() { 
     return chats; 
    } 

    /** 
    * @param chats 
    *   the chats to set 
    */ 
    public void setChats(List<Chat> chats) { 
     this.chats = chats; 
    } 

    public Chat addChat(Chat chat) { 
     getChats().add(chat); 
     chat.setUserRegistration(this); 

     return chat; 
    } 

    public Chat removeChat(Chat chat) { 
     getChats().remove(chat); 
     chat.setUserRegistration(null); 

     return chat; 
    } 

    public List<Coupon> getCoupons() { 
     return this.coupons; 
    } 

    public void setCoupons(List<Coupon> coupons) { 
     this.coupons = coupons; 
    } 

    public Coupon addCoupon(Coupon coupon) { 
     getCoupons().add(coupon); 
     coupon.setUserRegistration(this); 

     return coupon; 
    } 

    public Coupon removeCoupon(Coupon coupon) { 
     getCoupons().remove(coupon); 
     coupon.setUserRegistration(null); 

     return coupon; 
    } 

    public List<DeviceDetail> getDeviceDetails() { 
     return this.deviceDetails; 
    } 

    public void setDeviceDetails(List<DeviceDetail> deviceDetails) { 
     this.deviceDetails = deviceDetails; 
    } 

    public DeviceDetail addDeviceDetail(DeviceDetail deviceDetail) { 
     getDeviceDetails().add(deviceDetail); 
     deviceDetail.setUserRegistration(this); 

     return deviceDetail; 
    } 

    public DeviceDetail removeDeviceDetail(DeviceDetail deviceDetail) { 
     getDeviceDetails().remove(deviceDetail); 
     deviceDetail.setUserRegistration(null); 

     return deviceDetail; 
    } 

    public List<Portfolio> getPortfolios() { 
     return this.portfolios; 
    } 

    public void setPortfolios(List<Portfolio> portfolios) { 
     this.portfolios = portfolios; 
    } 

    public Portfolio addPortfolio(Portfolio portfolio) { 
     getPortfolios().add(portfolio); 
     portfolio.setUserRegistration(this); 

     return portfolio; 
    } 

    public Portfolio removePortfolio(Portfolio portfolio) { 
     getPortfolios().remove(portfolio); 
     portfolio.setUserRegistration(null); 

     return portfolio; 
    } 

    public List<UserDetail> getUserDetails() { 
     return this.userDetails; 
    } 

    public void setUserDetails(List<UserDetail> userDetails) { 
     this.userDetails = userDetails; 
    } 

    public UserDetail addUserDetail(UserDetail userDetail) { 
     getUserDetails().add(userDetail); 
     userDetail.setUserRegistration(this); 

     return userDetail; 
    } 

    public UserDetail removeUserDetail(UserDetail userDetail) { 
     getUserDetails().remove(userDetail); 
     userDetail.setUserRegistration(null); 

     return userDetail; 
    } 

    public List<UserLoginDetail> getUserLoginDetails() { 
     return this.userLoginDetails; 
    } 

    public void setUserLoginDetails(List<UserLoginDetail> userLoginDetails) { 
     this.userLoginDetails = userLoginDetails; 
    } 

    public UserLoginDetail addUserLoginDetail(UserLoginDetail userLoginDetail) { 
     getUserLoginDetails().add(userLoginDetail); 
     userLoginDetail.setUserRegistration(this); 

     return userLoginDetail; 
    } 

    public UserLoginDetail removeUserLoginDetail(UserLoginDetail userLoginDetail) { 
     getUserLoginDetails().remove(userLoginDetail); 
     userLoginDetail.setUserRegistration(null); 

     return userLoginDetail; 
    } 

    public UserRoleMaster getUserRoleMaster() { 
     return this.userRoleMaster; 
    } 

    public void setUserRoleMaster(UserRoleMaster userRoleMaster) { 
     this.userRoleMaster = userRoleMaster; 
    } 

    public List<Watch> getWatches() { 
     return this.watches; 
    } 

    public void setWatches(List<Watch> watches) { 
     this.watches = watches; 
    } 

    public Watch addWatch(Watch watch) { 
     getWatches().add(watch); 
     watch.setUserRegistration(this); 

     return watch; 
    } 

    public Watch removeWatch(Watch watch) { 
     getWatches().remove(watch); 
     watch.setUserRegistration(null); 

     return watch; 
    } 

}