- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
为什么我在验证失败时从 Hibernate 收到 UnsupportedOperationException?我希望出现 ConstraintViolationException。
下面是我的 DAO。当它通过验证时,它工作正常。我正在使用 Hibernate 和 Hibernate Validator 4。我正在使用 Websphere 8.0。我认为 WebSphereExtendedJtaPlatform 是罪魁祸首,但我不知道为什么。
如果我查看所谓的 WebSphereExtendedJtaPlatform 源代码(点击源代码链接),看起来那里的大多数方法都只是抛出 UnsupportedOperationException。
这是我的堆栈跟踪:
org.hibernate.AssertionFailure <init> HHH000099: an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session): org.hibernate.AssertionFailure: null id in com.westfieldgrp.beanvalidation.persistence.Car entry (don't flush the Session after an exception occurs)
[11/14/12 16:48:48:785 EST] 00000020 RegisteredSyn E WTRN0074E: Exception caught from before_completion synchronization operation: java.lang.UnsupportedOperationException
at org.hibernate.service.jta.platform.internal.WebSphereExtendedJtaPlatform$TransactionManagerAdapter.setRollbackOnly(WebSphereExtendedJtaPlatform.java:139)
我的堆栈跟踪中的另一个有趣片段:
Entity manager factory name (src_persistence) is already registered. If entity manager will be clustered or passivated, specify a unique value for property 'hibernate.ejb.entitymanager_factory_name'
这是类
package com.westfieldgrp.pom.data.dao;
import java.util.ArrayList;
import java.util.Set;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.RollbackException;
import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import com.westfieldgrp.beanvalidation.persistence.Car;
import com.westfieldgrp.beanvalidation.persistence.Driver;
import com.westfieldgrp.beanvalidation.persistence.Person;
public class CarDAO {
private EntityManager entityManager;
public void save(Person convertedPerson, Driver convertedDriver, Car convertedCar, FacesContext facesContext) throws ConstraintViolationException{
EntityManager em = getEntityManager();
//em.setFlushMode(FlushModeType.COMMIT);
if("test".equals(convertedPerson.getName())){ // To test JPA validation
convertedPerson.setName(null);
}
//Person savedPerson = em.merge(convertedPerson);
try {
//em.merge(convertedPerson);
em.persist(convertedPerson);
em.flush();
} catch (Exception e) {
System.out.println("*******" + getRootCause(e));
}
}
private String getRootCause(Throwable e){
if(e.getCause() != null){
return getRootCause(e.getCause());
} else {
return e.toString();
}
}
public EntityManager getEntityManager() {
EntityManagerFactory emf = Persistence.createEntityManagerFactory("src_persistence");
entityManager = emf.createEntityManager();
return entityManager;
}
public void setEntityManager(EntityManager entityManager) {
this.entityManager = entityManager;
}
}
个人实体:
package com.westfieldgrp.beanvalidation.persistence;
import java.io.Serializable;
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.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import org.hibernate.validator.constraints.Length;
/**
* The persistent class for the PERSON database table.
*
*/
@Entity
@Table(name="PERSON")
public class Person implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="PERSON_ID")
private int personId;
@Column(name="NAME")
@NotNull(message = "A name is required.")
//@Length(min = 5, message = "Need a longer name.")
private String name;
@Column(name="EMAIL")
@NotNull(message = "An email is required.")
//@Pattern(regexp="[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?", message="Invalid email format.")
private String email;
public Person() {
}
public int getPersonId() {
return this.personId;
}
public void setPersonId(int personId) {
this.personId = personId;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public void setEmail(String email) {
this.email = email;
}
public String getEmail() {
return email;
}
}
整个堆栈跟踪:
[11/14/12 19:00:53:202 EST] 0000003c EntityManager Z org.hibernate.ejb.internal.EntityManagerFactoryRegistry addEntityManagerFactory HHH000436: Entity manager factory name (src_persistence) is already registered. If entity manager will be clustered or passivated, specify a unique value for property 'hibernate.ejb.entitymanager_factory_name'
[11/14/12 19:00:53:214 EST] 0000003c SystemOut O *******java.lang.UnsupportedOperationException
[11/14/12 19:00:53:214 EST] 0000003c AssertionFail Z org.hibernate.AssertionFailure <init> HHH000099: an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session): org.hibernate.AssertionFailure: null id in com.westfieldgrp.beanvalidation.persistence.Person entry (don't flush the Session after an exception occurs)
[11/14/12 19:00:53:215 EST] 0000003c RegisteredSyn E WTRN0074E: Exception caught from before_completion synchronization operation: java.lang.UnsupportedOperationException
at org.hibernate.service.jta.platform.internal.WebSphereExtendedJtaPlatform$TransactionManagerAdapter.setRollbackOnly(WebSphereExtendedJtaPlatform.java:139)
at org.hibernate.engine.transaction.internal.jta.CMTTransaction.markRollbackOnly(CMTTransaction.java:131)
at org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl.setRollbackOnly(TransactionCoordinatorImpl.java:305)
at org.hibernate.engine.transaction.synchronization.internal.SynchronizationCallbackCoordinatorImpl.setRollbackOnly(SynchronizationCallbackCoordinatorImpl.java:118)
at org.hibernate.engine.transaction.synchronization.internal.SynchronizationCallbackCoordinatorImpl.beforeCompletion(SynchronizationCallbackCoordinatorImpl.java:108)
at org.hibernate.engine.transaction.synchronization.internal.RegisteredSynchronization.beforeCompletion(RegisteredSynchronization.java:53)
at org.hibernate.service.jta.platform.internal.WebSphereExtendedJtaPlatform$TransactionManagerAdapter$TransactionAdapter$1.invoke(WebSphereExtendedJtaPlatform.java:176)
at $Proxy56.beforeCompletion(Unknown Source)
at com.ibm.ws.jtaextensions.SynchronizationCallbackWrapper.beforeCompletion(SynchronizationCallbackWrapper.java:66)
at com.ibm.tx.jta.impl.RegisteredSyncs.coreDistributeBefore(RegisteredSyncs.java:291)
at com.ibm.ws.tx.jta.RegisteredSyncs.distributeBefore(RegisteredSyncs.java:152)
at com.ibm.ws.tx.jta.TransactionImpl.prePrepare(TransactionImpl.java:2332)
at com.ibm.ws.tx.jta.TransactionImpl.stage1CommitProcessing(TransactionImpl.java:553)
at com.ibm.tx.jta.impl.TransactionImpl.processCommit(TransactionImpl.java:1014)
at com.ibm.tx.jta.impl.TransactionImpl.commit(TransactionImpl.java:948)
at com.ibm.ws.tx.jta.TranManagerImpl.commit(TranManagerImpl.java:379)
at com.ibm.tx.jta.impl.TranManagerSet.commit(TranManagerSet.java:181)
at com.ibm.ejs.csi.TranStrategy.commit(TranStrategy.java:922)
at com.ibm.ejs.csi.TranStrategy.postInvoke(TranStrategy.java:234)
at com.ibm.ejs.csi.TransactionControlImpl.postInvoke(TransactionControlImpl.java:579)
at com.ibm.ejs.container.EJSContainer.postInvoke(EJSContainer.java:4755)
at com.westfieldgrp.ejb.EJSLocalNSLCarSessionBean_f700c086.save(EJSLocalNSLCarSessionBean_f700c086.java)
at com.westfieldgrp.beans.CarBean.processCar(CarBean.java:35)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:611)
at org.apache.el.parser.AstValue.invoke(AstValue.java:262)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278)
at org.apache.myfaces.view.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:83)
at javax.faces.component._MethodExpressionToMethodBinding.invoke(_MethodExpressionToMethodBinding.java:88)
at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:100)
at javax.faces.component.UICommand.broadcast(UICommand.java:120)
at javax.faces.component.UIViewRoot._broadcastAll(UIViewRoot.java:973)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:275)
at javax.faces.component.UIViewRoot._process(UIViewRoot.java:1285)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:711)
at org.apache.myfaces.lifecycle.InvokeApplicationExecutor.execute(InvokeApplicationExecutor.java:34)
at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:171)
at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:189)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1147)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:722)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:449)
at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178)
at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1020)
at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:87)
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:883)
at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1659)
at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:195)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:452)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:511)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:305)
at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:83)
at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1648)
最佳答案
我最终根据以下链接修改了 WebSphereExtendedJtaPlatform 代码。我很困惑为什么那个类基本上没有实现。
关于java - Hibernate 验证失败时意外的 UnsupportedOperationException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13388069/
我一直在开发搜索功能,该功能使我能够在 RecyclerView 中搜索数据。当我单击搜索图标时,我的应用程序崩溃了。经过一些调试后,我发现了问题,似乎无法清除信息或将信息添加到新列表。 Adapte
我已经创建了一个 ContainerRequestfilter 并成功触发了它。现在我想访问我之前在 grizzly HttpServerProbe 中设置的 UserPrincipal,如下所示:
我试图获取特定于区域设置的百分比符号。我的崩溃日志在尝试从 DecimalFormatSymbols 获取百分比时显示“UnsupportedOperationException”。 我使用给定区域设
我在下面编写了代码,我不知道出了什么问题,但 validDatesIterator.remove() 给了我 UnsupportedOperationException 异常。使用java 1.6 L
我正在尝试制作一个包含名称的列表。该列表应该是可修改的(添加、删除、排序等)。但是,每当我尝试更改 ArrayAdapter 中的项目时,程序都会崩溃,并出现 java.lang.Unsupporte
所以,我目前正在编写一个方法来迭代目录以及该目录内的所有目录: public static Set iterateDirectory(String dir){ Set children = n
我正在开发一个滑雪追踪器应用程序,但我在第一个任务上失败了:)秒表 这是我的服务: public class TrackerService extends Service { private
当运行以下代码时,我遇到一个异常,它简单地说:线程“LWJGL Application”中出现异常 java.lang.UnsupportedOperationException // Declare
这个问题已经有答案了: remove() on List created by Arrays.asList() throws UnsupportedOperationException (3 个回答)
String[] aArr = ...; String[] bArr = ...; List images = Arrays.asList(aArr); images.addA
我是 facebook sdk 的新手,所以我不太确定为什么会收到此错误。我已将其缩小到此部分: List permissions = session.getPermissions()
调用 add() 时出现 UnsupportedOperationException在以下代码中: Collection myClass = method(); MyClass newObject =
代码如下: private static Map> merge(Map> m1, Map> m2) { Map> mx = new HashMap>(); for (Entry> en
我有这个代码: public static String SelectRandomFromTemplate(String template,int count) { String[] split
所以其中一个方法的描述如下: public BasicLinkedList addToFront(T data) This operation is invalid for a sorted list
我正在使用 Grails 2.3.11 并使用 MongoDb 插件 mongodb:3.0.3。 我的代码是这样的: def home() { List abcs = ABC.list()
我正在尝试创建一个自定义 ListView 来保存自定义对象的 View ,在这种情况下,自定义对象将是 Data 类的实例 Java 代码如下: import android.app.ListAct
我不太明白在哪里可以抛出这个异常。 例如,我正在实现 Future接口(interface)并且不希望任何人调用该方法: Future#get(long, TimeUnit) . 那么,我可以直接扔掉
我有下面的示例代码: String[] patternArray = {"1","2","3"}; List patternCheck = Arrays.asList(patternArray); p
在研究 Collection API 时,我们发现某些方法(add、remove、...)可能会抛出 java.lang.UnsupportedOperationException 如果 Collec
我是一名优秀的程序员,十分优秀!