如何在Grails4中集成java类的HibernateXML映射?
我正试图通过grails应用程序中的HibernateXML映射配置映射POJO。这在grails 2.x版本中运行良好,但在grails 4中,它没有采用hibernate配置,该配置位于:如何在Grails4中集成java类的HibernateXML映射?,java,hibernate,grails,gorm,grails-4,Java,Hibernate,Grails,Gorm,Grails 4,我正试图通过grails应用程序中的HibernateXML映射配置映射POJO。这在grails 2.x版本中运行良好,但在grails 4中,它没有采用hibernate配置,该配置位于: grails-app/conf/hibernate.cfg.xml src/main/java/com/prabin/Prabin.java 这是什么 <?xml version='1.0' encoding='UTF-8'?> <!DOCTYPE hibernate-configu
grails-app/conf/hibernate.cfg.xml
src/main/java/com/prabin/Prabin.java
这是什么
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
'-//Hibernate/Hibernate Configuration DTD 3.0//EN'
'http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd'>
<hibernate-configuration>
<session-factory>
<mapping resource='com.prabin.test.hbm.xml'/>
</session-factory>
</hibernate-configuration>
即:
package com.prabin;
public class Prabin {
Integer id;
// Getters and Setters
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
}
应用程序没有使用hibernate配置文件,因此没有为我的pojo创建任何表。Hibernate配置文件被完全忽略。Grails支持团队帮助我完成了这一过程,过程如下: hibernate映射文件:
hibernate.mapping.xml
应位于/src/main/resources目录中,并映射到application.yml中,如下所示:
hibernate:
mappingLocations: classpath:hibernate.mapping.xml
注意:实体文件应该是一个groovy文件,映射有@Entity
和继承接口GormEntity
注释,以支持groovy的动态查找程序
例如:
@Entity
class Employee implements GormEntity<Employee> {
Integer id
String firstName
String lastName
Double salary
}
@实体
类Employee实现GormEntity{
整数id
字符串名
字符串姓氏
双薪
}
休眠映射:
<?xml version = "1.0" encoding = "utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name = "com.objectcomputing.example.Employee" table = "EMPLOYEE">
<meta attribute = "class-description">
This class contains the employee detail.
</meta>
<id name = "id" type = "int" column = "id">
<generator class="native"/>
</id>
<property name = "firstName" column = "first_name" type = "string"/>
<property name = "lastName" column = "last_name" type = "string"/>
<property name = "salary" column = "salary" type = "double"/>
</class>
</hibernate-mapping>
此类包含员工详细信息。
下面是完整的工作示例:Grails支持团队帮助我完成了这一过程,流程如下: hibernate映射文件:
hibernate.mapping.xml
应位于/src/main/resources目录中,并映射到application.yml中,如下所示:
hibernate:
mappingLocations: classpath:hibernate.mapping.xml
注意:实体文件应该是一个groovy文件,映射有@Entity
和继承接口GormEntity
注释,以支持groovy的动态查找程序
例如:
@Entity
class Employee implements GormEntity<Employee> {
Integer id
String firstName
String lastName
Double salary
}
@实体
类Employee实现GormEntity{
整数id
字符串名
字符串姓氏
双薪
}
休眠映射:
<?xml version = "1.0" encoding = "utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name = "com.objectcomputing.example.Employee" table = "EMPLOYEE">
<meta attribute = "class-description">
This class contains the employee detail.
</meta>
<id name = "id" type = "int" column = "id">
<generator class="native"/>
</id>
<property name = "firstName" column = "first_name" type = "string"/>
<property name = "lastName" column = "last_name" type = "string"/>
<property name = "salary" column = "salary" type = "double"/>
</class>
</hibernate-mapping>
此类包含员工详细信息。
下面是一个完整的工作示例:如果使用
grails-app/conf/hibernate/
目录来保存配置文件,它可以工作吗?@JeffScottBrown也不可以。如果使用grails-app/conf/hibernate/
目录来保存配置文件,它可以工作吗?@JeffScottBrown也不可以。