EclipseLink在Netbeans上不起作用,这正常吗? [英] EclipseLink does not work on Netbeans, is this normal?

查看:74
本文介绍了EclipseLink在Netbeans上不起作用,这正常吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将停留在EclipseLink上数周.我无法在数据库中保留对象.我使用netbeans 7.3.当我开始设计Web应用程序时遇到了这个问题.接下来是我采用的方法.可能是因为我没有意识到自己的错误.

It'll be weeks that I'm stuck with EclipseLink. I can not persist an object in my database. I use netbeans 7.3. I encountered this problem when I started designing a web application. What follows is the approach I have adopted. It may be that I do without me realize a mistake.

在netbeans完成生成项目文件之后,我配置了jndi.然后,我使用实体对象中的数据库表netbeans自动进行了转换. 这是链接

After that netbeans has finished generating the project files I configured the jndi. Then I converted automatically with netbeans, the database tables in entity object. here is the link

然后,从这些类中,我创建了它们的 JPAController . (始终自动与netbeans一起使用)

then, from these classes, I created their JPAController . (Always automatically with netbeans)

最后,作为测试,我仅实例化了"Outils"的描述,并将字段ID保留为空.由于后者会自动在数据库中增加,因此如果持久性做得很好,那么在没有控制台的情况下我应该有一个id.

and finally, as a test, I just instantiate the description of "Outils" and leave the fields empty id. Since the latter automatically increment in the database, if the persistence is done well, I should have an id when I appear with out the console.

<body>
    <h1>Hello World!</h1>
    <%
       Outils o = new Outils();
       o.setDesignation("hammers");

       EntityManagerFactory emf = Persistence.createEntityManagerFactory("Test_EclipseLinkPU");
       UserTransaction utx = (UserTransaction) new InitialContext().lookup("java:comp/UserTransaction");

       OutilsJpaController o_ctrl = new OutilsJpaController(utx, emf);
       o_ctrl.create(o);

       out.println("this is the id of hammer " + o.toString());
    %>
</body>

我得到的结果是:Outils [id = null].

and I get as result: Outils[ id=null ].

我没有错误,关于调试器也没什么问题.

I have no error or on glassfish even less about the debugger.

Ps:这是persistence.xml文件

Ps : Here are the persistence.xml file

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
    <persistence-unit name="Test_EclipseLinkPU" transaction-type="JTA">
        <jta-data-source>test_data_source</jta-data-source>
        <exclude-unlisted-classes>false</exclude-unlisted-classes>
        <properties/>
    </persistence-unit>
</persistence>

感谢您的未来,感谢您的回答,并在聆听任何其他信息.

Thank you for your future is in your answers and listening for any additional information.

推荐答案

在将任何内容写入数据库之前,您需要提交或刷新事务.如果您使用的是IDENTITY排序(我强烈建议您不要使用IDENTITY,如果db支持,请使用TABLE或SEQUENCE),然后才能在插入发生之前分配ID,因此persist()将不会分配ID(就像对ID所做的那样)表和序列).

You need to commit or flush the transaction before anything will be written to the database. If you are using IDENTITY sequencing (I strongly recommend not using IDENTITY, use TABLE or SEQUENCE if db supports it), then the Id cannot be allocated until the insert occurs, so a persist() will not assign the Id (as it does for TABLE and SEQUENCE).

您的create()方法有什么作用?您的ID如何映射?

What does your create() method do? How is your Id mapped?

这篇关于EclipseLink在Netbeans上不起作用,这正常吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆