Tag: eclipselink

如何使用JPA生命周期事件来获取实体数据

我有一个RESTful API,它使用了一个用@EntityListners注释的实体类。 在EntityListner.java中,我有一个用@PostPersist注释的方法。 因此,当该事件触发时,我想要提取有关刚刚保存到数据库的实体的所有信息。 但是,当我尝试这样做时,Glassfish正在生成exception,并且EntityListner类中的方法未按预期执行。 这是代码 public class EntityListner { private final static String QUEUE_NAME = “customer”; @PostUpdate @PostPersist public void notifyOther(Customer entity){ CustomerFacadeREST custFacade = new CustomerFacadeREST(); Integer customerId = entity.getCustomerId(); String custData = custFacade.find(customerId).toString(); String successMessage = “Entity added to server”; try{ ConnectionFactory factory = new ConnectionFactory(); factory.setHost(“localhost”); Connection connection = factory.newConnection(); Channel […]

与jpa和eclipselink的jndi数据库连接

我尝试在Java中使用JNDI在Tomcat 5.5上结合eclipseLink / JPA设置数据库连接。 我已经在web.xml和context.xml中配置了JNDI资源。 数据库连接与JNDI一起使用,而不使用JPA和eclipseLink。 在为eclipseLink配置persistence.xml之后,我得到了以下exception。 我不知道如何正确配置persistence.xml以使用JNDI数据源进行数据库连接。 例外 WicketMessage: Method onFormSubmitted of interface org.apache.wicket.markup.html.form.IFormSubmitListener targeted at component [MarkupContainer [Component id = loginForm]] threw an exception Root cause: javax.naming.NamingException: This context must be accessed throught a java: URL at org.apache.naming.SelectorContext.parseName(SelectorContext.java:686) at org.apache.naming.SelectorContext.lookup(SelectorContext.java:121) at javax.naming.InitialContext.lookup(InitialContext.java:396) at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:110) at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:94) at org.eclipse.persistence.sessions.DatasourceLogin.connectToDatasource(DatasourceLogin.java:16 2) at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(Datab aseSessionImpl.java:579) at […]

没有为Metamodel中的密钥类找到

实体: @Entity @Table(name=”user_account”) public class UserAccount implements Serializable{ private static final long serialVersionUID = -2606506548742732094L; @Id @GeneratedValue(strategy=GenerationType.TABLE) private Integer id; persistence.xml中 false 错误 WARNING: #{accountController.performLogin}: java.lang.IllegalArgumentException: No [EntityType] was found for the key class [com.maze.model.UserAccount] in the Metamodel – please verify that the [Entity] class was referenced in persistence.xml using a specific com.maze.model.UserAccount property or […]

如何告诉JPA首选的DataType

如果我使用JPA(EclipseLink)创建表,则String类型会生成varchar2(255)。 我怎么能告诉JPA(通过Annotation)创建一个varchar2(20)属性。 如果我有一个List JPA创建一个BLOB(4000)但我想要一个varchar2(我的序列化对象的字符串很短) 这怎么可能? 我必须手工完成吗?

即使实体标有@Entity注释,也会显示未知的实体类错误消息

我正在使用Netbean6.9.1和JPA EclipseLink构建REST Web应用程序。 我面临的问题是即使我的实体类MasatoTable标有Entity注释,我也会收到错误: (java.lang.IllegalArgumentException: Unknown entity bean class: class entity.MasatoTable, please verify that this class has been marked with the @Entity annotation.) 问题是当我从NetbeanIDE重新启动GlassFish3服务器时,它会工作一段时间,不知怎的,在某些时候,错误开始出现。 我以前使用Toplink Essential并没有问题,但我已经改为EclipseLink并重新定义persistence.xml(如下所示)并且此问题已经开始。 但我没有看到任何我能想到的代码错误.. MasatoTable.java @Entity @Table(name = “MasatoTable”) public class MasatoTable implements Serializable { …continue code… persistence.xml中 org.eclipse.persistence.jpa.PersistenceProvider jdbc/koga_kojo entity.MasatoTable 看起来像是同一个问题,但该票证的解决方案是从Eclipselink回滚到Toplink。 有没有人解决这个问题而不回滚到toplink? 热部署后的未知实体bean类:netbeans 6.9 + glassfish 2.1 + eclipselink jpa 2.0 […]

必须管理实体以调用删除

这里发生了什么? @Stateless @LocalBean public class AppointmentCommentDao { public void delete(long appointmentCommentId) { AppointmentComment ac = em.find(AppointmentComment.class, appointmentCommentId); if (ac != null) { em.merge(ac); em.remove(ac); } } @PersistenceContext private EntityManager em; } 在remove调用时,我得到一个IllegalArgumentException ,消息为Entity must be managed to call remove: …., try merging the detached and try the remove again.

用于JPA的Hibernate或EclipseLink?

我想知道是否有人有任何这些框架的JPA2.0实现经验? 特别是与Spring3.x一起提供EclipseLink支持。 您是否使用这些框架和JPA2.0中的任何一个进行生产? 任何严重的问题?

使用EclipseLink在JPA 2.1中注册转换器

在JavaEE环境中,我使用EclipseLink的JPA 2.1实现, 我有一些包含enums实体。 所以我为这些枚举创建了转换器。 汽车实体: @Entity public class Car implements Serializable { private static final long serialVersionUID = 6L; @Id private String id; @Convert (converter = CarColorConverter.class) private CarColor color; public enum CarColor { Black, Gray, White, Red }; public Car () { id = GenerateUUID.id (); } …. } CarColor转换器: @Converter (converterClass = CarColorConverter.class, […]

JPA当前没有交易活动

将JPA与EclipseLink实现一起使用。 码: try{ if(!em.getTransaction().isActive()) em.getTransaction().begin(); System.out.println(2); em.persist(currentUser); System.out.println(3); if (em.getTransaction().isActive()){ System.out.println(“IS ACTIVE”); } else { System.out.println(“NO ACTIVE”); } em.getTransaction().commit(); System.out.println(4); } catch (Exception e){ completed = false; em.getTransaction().rollback(); System.out.println(“ERROR: ” + e.getMessage()); } 错误: INFO: persistOne – Enter INFO: 2 INFO: 3 INFO: IS ACTIVE INFO: [EL Warning]: 2012-01-06 14:45:59.221–UnitOfWork(12492659)–java.lang.IllegalStateException: During synchronization a new object […]

Eclipselink忽略具有lambda表达式的实体类

我正在使用EclipseLink(2.5.1,也尝试过2.5.2-M1)构建一个java SE 8(oracle 1.8.0-b129)应用程序,并且有一个Entity类,它被EclipeLink忽略,尽管被正确注释并且在persistence.xml文件中引用。 日志显示没有提及类,没有为它生成模式,等等。使用实体给出’抽象模式类型未知’错误。 我想我终于找到了原因,并认为我会分享。 显然,EclipseLink不喜欢带有lambda表达式的类。 这是一个简单的类,可以重现问题: @Entity public class LambdaEntity { @Id private Integer id; public void theLambda() { Arrays.asList(1, 2, 3).stream().filter(m -> m == 2); } } lambda表达式甚至不必使用持久属性,它在类中的简单存在就足够了。 有谁知道这会导致什么? 我猜测EclipeLink会对生成的字节码产生影响,但我发现很奇怪它会默默地忽略该类。 如果您尝试在与其他实体的关联中使用此实体,EclipseLink将提供错误,指出实体未在persistence.xml文件中定义。 stacktrace的一部分: Local Exception Stack: Exception [EclipseLink-30005] (Eclipse Persistence Services – 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.PersistenceUnitLoadingException Exception Description: An exception was thrown while searching for […]