hibernate 逆向工程包含 @Transient 属性
我试图将以下内容包含
private org.springframework.web.multipart.commons.CommonsMultipartFile photo;
@Transient
public CommonsMultipartFile getPhoto() {
return photo;
}
public void setPhoto(CommonsMultipartFile photo) {
this.photo = photo;
}
在从数据库表生成的 pojo 类中。
我研究发现有一种方法可以提及额外的类代码 在元标记中,如下
http://www.scribd。 com/doc/23123635/30/Guiding-the-reverse-engineering-process
但这不允许添加属性变量 photo。
请建议我如何在 reveng.xml 中做到这一点,以便 每次运行 hbm2java 时都会包含此代码。
提前致谢!
I am trying to include following
private org.springframework.web.multipart.commons.CommonsMultipartFile photo;
@Transient
public CommonsMultipartFile getPhoto() {
return photo;
}
public void setPhoto(CommonsMultipartFile photo) {
this.photo = photo;
}
in my pojo class generated from database table.
I have studied to find there is a way to mention extra class code
in meta tag like following
http://www.scribd.com/doc/23123635/30/Guiding-the-reverse-engineering-process
but this does not allow to add property variable photo.
Please suggest a way how can I do it in reveng.xml so that
this code is included on every run of hbm2java.
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 reveng 模板来实现此类自定义代码。如果打开 hibernate-tools.jar,您将在 pojo 文件夹中找到 .ftl 文件。您需要覆盖它们才能放置自定义代码。
步骤:
如果您使用 Maven,则将其放在
componentProperties
下以实现 hbm2java 目标:在资源下创建
revenge.templates/pojo
文件夹。确保文件夹名称始终为pojo
,否则无法检测到覆盖。创建
pojo.ftl
文件并复制 jar 中存在的pojo.ftl
文件中的内容。在此文件中添加所有导入语句。类似地,按照其他文件查找您想要将自定义代码放置的确切位置。
You can achieve such custom code by using reveng templates. If you open
hibernate-tools.jar
you will find .ftl files in thepojo
folder. You need to override them to put custom code.Steps:
If you are using maven then put this under
componentProperties
for hbm2java goal:Create
revenge.templates/pojo
folder under resources. Make sure that the folder name is alwayspojo
, otherwise the overrides are not detected.Create
pojo.ftl
file and copy the contents from thepojo.ftl
file present in the jar. Add all the import statements in this file.Similarly, follow the other files to find out where exactly you want to put the custom code.
据我所知,没有办法在 reveng.xml 或自定义 ReverseEngineeringStrategy 中指定这一点。
我解决这个问题的方法是使用自定义类层扩展所有生成的基本 POJO 类,并在其中添加瞬态属性和特殊行为。不完全符合您的要求,但它运行良好,并且在不牺牲代码生成的好处的情况下提供了灵活性。
As far as I know there's no way to specify this in either reveng.xml or a custom ReverseEngineeringStrategy.
The way I solve this problem is by extending all of my generated base POJO classes with a custom class layer, and adding transient properties and special behaviors there. Not exactly what you were asking, but it works well and allows for flexibility without sacrificing the benefits of code generation.