gpt4 book ai didi

java - PersistenceUnit [...] 的部署失败。关闭此 PersistenceUnit 的所有工厂

转载 作者:行者123 更新时间:2023-11-29 05:17:47 26 4
gpt4 key购买 nike

我在调用 hentMeldinger() 时不断收到此错误;

public class Kontroll {
private EntityManagerFactory emf;

Kontroll() {
emf = Persistence.createEntityManagerFactory("meldingsTing");
}

public List<Melding> hentMeldinger() {
EntityManager em = emf.createEntityManager();

TypedQuery<Melding> query = em.createQuery("SELECT o FROM Melding o",
Melding.class);// FIKS
List<Melding> meldinger = query.getResultList();

em.close();

return meldinger;
}
}

异常报告:

message Exception [EclipseLink-28019] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.EntityManagerSetupException

description The server encountered an internal error that prevented it from fulfilling this request.

exception

javax.persistence.PersistenceException: Exception [EclipseLink-28019] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Deployment of PersistenceUnit [meldingsTing] failed. Close all factories for this PersistenceUnit.
Internal Exception: Exception [EclipseLink-0] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.IntegrityException
Descriptor Exceptions:
---------------------------------------------------------

Exception [EclipseLink-63] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: The instance creation method [no.hib.dat104.oblig1.Melding.<Default Constructor>], with no parameters, does not exist, or is not accessible.
Internal Exception: java.lang.NoSuchMethodException: no.hib.dat104.oblig1.Melding.<init>()
Descriptor: RelationalDescriptor(no.hib.dat104.oblig1.Melding --> [DatabaseTable(MELDING)])

Runtime Exceptions:
---------------------------------------------------------

org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.createDeployFailedPersistenceException(EntityManagerSetupImpl.java:820)
org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:760)
org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getAbstractSession(EntityManagerFactoryDelegate.java:204)
org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.createEntityManagerImpl(EntityManagerFactoryDelegate.java:304)
org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:336)
org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:302)
no.hib.dat104.oblig1.Kontroll.lagreMelding(Kontroll.java:32)
no.hib.dat104.oblig1.MeldingServlet.doPost(MeldingServlet.java:83)
javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

根本原因:

Exception [EclipseLink-28019] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Deployment of PersistenceUnit [meldingsTing] failed. Close all factories for this PersistenceUnit.
Internal Exception: Exception [EclipseLink-0] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.IntegrityException
Descriptor Exceptions:
---------------------------------------------------------

Exception [EclipseLink-63] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: The instance creation method [no.hib.dat104.oblig1.Melding.<Default Constructor>], with no parameters, does not exist, or is not accessible.
Internal Exception: java.lang.NoSuchMethodException: no.hib.dat104.oblig1.Melding.<init>()
Descriptor: RelationalDescriptor(no.hib.dat104.oblig1.Melding --> [DatabaseTable(MELDING)])

Runtime Exceptions:
---------------------------------------------------------

org.eclipse.persistence.exceptions.EntityManagerSetupException.deployFailed(EntityManagerSetupException.java:238)
org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.createDeployFailedPersistenceException(EntityManagerSetupImpl.java:820)
org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:760)
org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getAbstractSession(EntityManagerFactoryDelegate.java:204)
org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.createEntityManagerImpl(EntityManagerFactoryDelegate.java:304)
org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:336)
org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:302)
no.hib.dat104.oblig1.Kontroll.lagreMelding(Kontroll.java:32)
no.hib.dat104.oblig1.MeldingServlet.doPost(MeldingServlet.java:83)
javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause

Exception [EclipseLink-0] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.IntegrityException
Descriptor Exceptions:
---------------------------------------------------------

Exception [EclipseLink-63] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: The instance creation method [no.hib.dat104.oblig1.Melding.<Default Constructor>], with no parameters, does not exist, or is not accessible.
Internal Exception: java.lang.NoSuchMethodException: no.hib.dat104.oblig1.Melding.<init>()
Descriptor: RelationalDescriptor(no.hib.dat104.oblig1.Melding --> [DatabaseTable(MELDING)])

Runtime Exceptions:
---------------------------------------------------------

org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:696)
org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:632)
org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:568)
org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.postConnectDatasource(DatabaseSessionImpl.java:799)
org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:743)
org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:239)
org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:685)
org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getAbstractSession(EntityManagerFactoryDelegate.java:204)
org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.createEntityManagerImpl(EntityManagerFactoryDelegate.java:304)
org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:336)
org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:302)
no.hib.dat104.oblig1.Kontroll.lagreMelding(Kontroll.java:32)
no.hib.dat104.oblig1.MeldingServlet.doPost(MeldingServlet.java:83)
javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

我的问题是,在查看此错误报告时,我不知道从哪里开始。我现在已经尝试了几个小时,但这对我来说毫无意义。如果有人能从中理解并解释,那就太棒了,但解决问题将是最好的。

最佳答案

Exception Description: The instance creation method [no.hib.dat104.oblig1.Melding.<Default Constructor>], with no parameters, does not exist, or is not accessible.

对于JPA实体,至少必须包含默认构造函数(无参数构造函数)

public Melding() {
}

关于java - PersistenceUnit [...] 的部署失败。关闭此 PersistenceUnit 的所有工厂,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25930949/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com