【问题标题】:How do I reverse Engineer with hibernate to get mapped superclass如何使用休眠进行逆向工程以获取映射的超类
【发布时间】:2017-12-18 10:23:24
【问题描述】:

我有六个表,其中包含许多公共字段。

十年前,我为 Hibernate 逆向工程指定了一些东西来创建一个映射的超类和六个扩展该类的类。

我可以手动完成,但我确信该功能必须仍然存在。

经过两个小时的谷歌搜索并看到手工制作的 pojos 示例,我找不到如何报复。

【问题讨论】:

  • 我不是要代码,我只是在任何地方都找不到文档。

标签: hibernate reverse-engineering mappedsuperclass


【解决方案1】:

我从来没有弄明白。相反,我编写了一个接口和一个抽象类,然后修改了生成的代码。

不漂亮,但它实际上对我有更多的好处。

奇怪的是,我扩展的类必须为每个属性都有一个 setter 方法,否则应用程序无法加载。

我创建了只抛出 UnsupportedOperationException 的设置器

现在如果可以在这个项目中获得两个源代码树,并让 hibernate 生成的目标类在没有这些废话的情况下编译。

apply() {
FILE=$1
echo $FILE
return
#https://stackoverflow.com/questions/11694980/using-sed-insert-a-line-below-or-above-the-pattern
#https://stackoverflow.com/questions/148451/how-to-use-sed-to-replace-only-the-first-occurrence-in-a-file
sed -i -e "0,/implements/{s/implements/extends AbstractDemand implements/}" $FILE

sed -i -e "3i  \
import com.techwanker.diamond.planning.AbstractDemand;\\n\
import com.techwanker.diamond.planning.AllocationMode;\\n\
import com.techwanker.diamond.planning.demand.DemandType;\\n\
" $FILE 
}

find_file() {
   file=`locate $1 | grep "^$PWD" | grep $1\$`
   return $file


rm -rf src/main/java
mvn hibernate3:hbm2java
apply `find_file ApsDmdOo.java`
apply `find_file ApsDmdSs.java`
apply `find_file ApsDmdFc.java`



cp -r src/main/java-required/java/* src/main/java
cp -r target/generated-sources/* src/main/java
mvn install

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-04-03
    • 2014-07-07
    • 1970-01-01
    • 2016-11-23
    • 2010-12-24
    • 1970-01-01
    • 1970-01-01
    • 2011-08-08
    相关资源
    最近更新 更多