@Stateless @Produces("text/plain") @Path("cc") public class HelloService { @EJB private DomainDao dao; @GET @Path("/put") public String put() { Domain d = new Domain(); d.setName("name"); d.setActive(true); d.setCreationDate(new Date()); d.setLastModificationDate(new Date()); dao.create(d); return "completed"; } @GET @Path("/get") public String get() { return dao.find(1l).getName(); } @GET @Path("/hello") public String message() { return "hi"; } }
[2015-10-23T18:53:47.137+0200] [glassfish 4.0] [WARNING] [] [javax.enterprise.web] [tid: _ThreadID=24 _ThreadName=http-listener-1(5)] [timeMillis: 1445619227137] [levelValue: 900] [[ StandardWrapperValve[pl.kacperb333.restApp.MainApp]: Servlet.service() for servlet pl.kacperb333.restApp.MainApp threw exception javax.transaction.xa.XAException: java.lang.IllegalStateException: This web container has not yet been started at com.sun.enterprise.resource.ConnectorXAResource.handleResourceException(ConnectorXAResource.java:115) at com.sun.enterprise.resource.ConnectorXAResource.rollback(ConnectorXAResource.java:215) at com.sun.enterprise.transaction.JavaEETransactionImpl.commit(JavaEETransactionImpl.java:488) at com.sun.enterprise.transaction.JavaEETransactionManagerSimplified.commit(JavaEETransactionManagerSimplified.java:854) at com.sun.ejb.containers.EJBContainerTransactionManager.completeNewTx(EJBContainerTransactionManager.java:719) at com.sun.ejb.containers.EJBContainerTransactionManager.postInvokeTx(EJBContainerTransactionManager.java:503) at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4475) at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2009) at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1979) at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:220) at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:88) at com.sun.proxy.$Proxy315.test(Unknown Source) at pl.kacperb333.restApp.webservices.__EJB31_Generated__HelloService__Intf____Bean__.test(Unknown Source) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:81) at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:125) at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$TypeOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:195) at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:91) at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:346) at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:341) at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:101) at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:224) at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271) at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267) at org.glassfish.jersey.internal.Errors.process(Errors.java:315) at org.glassfish.jersey.internal.Errors.process(Errors.java:297) at org.glassfish.jersey.internal.Errors.process(Errors.java:267) at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317) at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:198) at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:946) at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:323) at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:372) at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:335) at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:218) at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673) at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174) at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:357) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:260) at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:188) at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191) at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168) at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189) at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119) at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288) at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206) at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136) at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114) at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77) at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838) at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113) at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115) at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55) at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135) at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564) at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544) at java.lang.Thread.run(Thread.java:745) ]]
我已经在这个问题上工作了两天了,现在我没有主意了。
下面是entity和dao类:
抽象性:
@MappedSuperclass public abstract class AbstractEntity implements IAbstractEntity { private Boolean active; @Temporal(TemporalType.DATE) private Date creationDate; @Temporal(TemporalType.DATE) private Date lastModificationDate; @Override public Boolean getActive() { return active; } @Override public void setActive(Boolean active) { this.active = active; } @Override public Date getCreationDate() { return creationDate; } @Override public void setCreationDate(Date creationDate) { this.creationDate = creationDate; } @Override public Date getLastModificationDate() { return lastModificationDate; } @Override public void setLastModificationDate(Date lastModificationDate) { this.lastModificationDate = lastModificationDate; } }
@Entity public class Domain extends AbstractEntity implements IDomain { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long domainId; @ManyToMany(targetEntity = Company.class, mappedBy = "domains") private Set companies; @OneToMany(targetEntity = Offer.class) @JoinColumn(name = "offerId") private List offers; private String name; @Override public Long getDomainId() { return domainId; } @Override public void setDomainId(Long domainId) { this.domainId = domainId; } @Override public Set getCompanies() { return companies; } @Override public void setCompanies(Set companies) { this.companies = companies; } @Override public List getOffers() { return offers; } @Override public void setOffers(List offers) { this.offers = offers; } @Override public String getName() { return name; } @Override public void setName(String name) { this.name = name; } }
public abstract class AbstractDao { private Class entityClass; public AbstractDao(Class entityClass) { this.entityClass = entityClass; } protected abstract EntityManager getEntityManager(); public void create(T entity) { getEntityManager().persist(entity); } public void edit(T entity) { getEntityManager().merge(entity); } public void remove(T entity) { getEntityManager().remove(getEntityManager().merge(entity)); } public T find(Object id) { return getEntityManager().find(entityClass, id); } public List findAll() { javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery(); cq.select(cq.from(entityClass)); return getEntityManager().createQuery(cq).getResultList(); } public List findRange(int[] range) { javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery(); cq.select(cq.from(entityClass)); javax.persistence.Query q = getEntityManager().createQuery(cq); q.setMaxResults(range[1] - range[0] + 1); q.setFirstResult(range[0]); return q.getResultList(); } public int count() { javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery(); javax.persistence.criteria.Root rt = cq.from(entityClass); cq.select(getEntityManager().getCriteriaBuilder().count(rt)); javax.persistence.Query q = getEntityManager().createQuery(cq); `enter code here`return ((Long) q.getSingleResult()).intValue(); } }
域道:
@Stateless @LocalBean public class DomainDao extends AbstractDao { @PersistenceContext(unitName = "rekruterPU") private EntityManager em; @Override protected EntityManager getEntityManager() { return em; } public DomainDao() { super(Domain.class); } }
我不认为问题出在EntityManager或dao类中,因为EntityManager(find())至少有一个方法起作用。我会很感激和帮忙的。
正如@kacperb333所建议的,标准持久性属性是EclipseLink中出现此错误的原因。
请勿使用:
<property name="javax.persistence.schema-generation.database.action" value="create"/>
请改用:
<property name="eclipselink.ddl-generation" value="create-or-extend-tables"/>
情况: 我有两个与OneTomany/ManyToone关系相关的实体。 想象一下,每个类也有一个名为id和getter和setter的PK。 问题: 如果我创建一个EntityA实例并设置一个与已经存在的EntityB实例的关系并持久化这个新实例,那么所有数据都会正确地保存到数据库中。但是,如果我从我的EntityManager请求EntityB的实例,它的列表中将不包含刚刚持久化的Entity
我是Spring靴的初学者,不能解决问题。我有一个实体类(Customer)和一个REST存储库(CustomerRepository)。类包含一些我不想被REST存储库公开的敏感字段。因此,我使用@jsonIgnore注释对这些字段进行了注释,如下所示: 一切正常,我的REST API返回了所需的结果。但是,当我向API发出POST请求以插入新实体时,我会收到数据库错误:。 在POST请求中,密
我有以下JPA实体类。和扩展Project的另一个实体OptProject。我正在使用InheritanceType.Jointed OptProject实体的JPA存储库如下 当我创建一个OptProject并尝试保存它时,我会得到下面的错误消息。这对我来说毫无意义,因为我使用@GeneratedValue(Streaty=GenerationType.Identity)为SQL server生
问题内容: 我在StackOverflow上遇到了类似的问题,尝试了解决方案,但没有找到答案。 我正在使用一种相当通用的JPA策略来设置某些实体的上次修改时间。设置列和字段,然后使用标记方法,并将其设置为等于当前时间。 问题是,我可以在调试器中看到正在调用该方法并且该字段正在更新,但是在我的数据库日志中,我仅看到一个SQL调用,以UPDATE更改字段,其中不包含timestamp字段的UPDATE
我正在尝试使用来持久化一个实体。当我自己处理事务时,我的测试用例工作(数据保存在db中)。 (实体管理器来自我的DAO类扩展的模板类) 当我配置spring来处理事务时,它会停止分发数据。 测试上下文。xml: UsersRepositoryTest: 堆栈跟踪: 从stacktrace中可以看到,事务似乎已经启动和完成,但没有生成sql插入,也没有数据插入到数据库中(数据回滚设置为false)
Akka持久化使有状态的actor能留存其内部状态,以便在因JVM崩溃、监管者引起,或在集群中迁移导致的actor启动、重启时恢复它。Akka持久化背后的关键概念是持久化的只是一个actor的内部状态的的变化,而不是直接持久化其当前状态 (除了可选的快照)。这些更改永远只能被附加到存储,没什么是可变的,这使得高事务处理率和高效复制成为可能。有状态actor通过重放保存的变化来恢复,从而使它们可以重