小编dis*_*ake的帖子

Spring JPA和persistence.xml

我正在尝试设置一个Spring JPA Hibernate简单示例WAR来部署到Glassfish.我看到一些示例使用persistence.xml文件,而其他示例则没有.一些示例使用dataSource,而另一些示例则不使用.到目前为止,我的理解是,如果我有以下情况,则不需要dataSource:

<persistence-unit name="educationPU"
    transaction-type="JTA">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <class>com.coe.jpa.StudentProfile</class>
    <properties>
        <property name="hibernate.connection.driver_class"
            value="com.mysql.jdbc.Driver" />
        <property name="hibernate.connection.url"
            value="jdbc:mysql://localhost:3306/COE" />
        <property name="hibernate.connection.username" value="root" />
        <property name="show_sql" value="true" />
        <property name="dialect" value="org.hibernate.dialect.MySQLDialect" />
    </properties>
</persistence-unit>
Run Code Online (Sandbox Code Playgroud)

我可以部署好,但是我的EntityManager没有被Spring注入.

我的applicationContext.xml:

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
    <property name="persistenceUnitName" value="educationPU" />
</bean>

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>

<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />

<tx:annotation-driven transaction-manager="transactionManager" />

<bean id="StudentProfileDAO" class="com.coe.jpa.StudentProfileDAO">
    <property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>

<bean id="studentService" class="com.coe.services.StudentService">
</bean>
Run Code Online (Sandbox Code Playgroud)

我的EntityManager类:

public class StudentService {
private String  saveMessage;
private String  showModal;
private String …
Run Code Online (Sandbox Code Playgroud)

java spring jpa

23
推荐指数
1
解决办法
12万
查看次数

Glass Kepler中没有Glassfish服务器库?

我正在使用Eclipse Kepler设置一个新的dev机器,以部署在Glassfish 3.1.2.2实例上.

当我去

project properties > java build path > libraries > add library > server runtime
Run Code Online (Sandbox Code Playgroud)

没有选项可以添加Glassfish服务器库.

关于我所做的一些其他注意事项(无论它们是否有帮助......):

  • 手动安装GF
  • 为Juno安装了OEPE
  • GF服务器已添加
  • GF Server启动/停止没问题(来自Eclipse)

我几乎在我的另一台机器上有相同的设置,除了我使用Juno而不是Kepler(但是,我尝试了上面的新Juno安装).那台机器一切正常但是刚刚建立起来了.据我所知,GF,Eclipse插件等有很多变化:https://blogs.oracle.com/piotrik/entry/glassfish_3_1_2_2 .那么也许它仍在工作中并没有完全准备好?

与此同时,我使用Modules文件夹中的Glassfish jar文件创建了一个用户库.不是理想的解决方案,但它现在有效.

但是,我仍然宁愿使用"更干净"的方法来添加服务器运行时.想法?

eclipse glassfish buildpath

11
推荐指数
1
解决办法
2万
查看次数

标签 统计

buildpath ×1

eclipse ×1

glassfish ×1

java ×1

jpa ×1

spring ×1