【发布时间】:2016-07-23 00:56:50
【问题描述】:
我在我的 java 项目中实现休眠 ORM。 我从github 下载了源代码 我已经编译了示例中包含的 hibernate-maven-web。 现在让我们假设我想在其中一个实现中重载方法 例如 CitizenDAOImpl.java 在我进行更改之前,它看起来像这样。
package sample.googlecode.genericdao.oldworld.dao;
import org.springframework.stereotype.Repository;
import sample.googlecode.genericdao.oldworld.model.Citizen;
/**
* <p>
* This is the implementation of the Citizen DAO. You can see that we don't
* actually have to implement anything, it is all inherited from GenericDAOImpl
* through BaseDAO. We just specify the entity type (Citizen) and its identifier
* type (Long).
*
* <p>
* The @Repository allows Spring to recognize this as a managed component (so we
* don't need to specify it in XML) and also tells spring to do DAO exception
* translation to the Spring exception hierarchy.
*
* @author dwolverton
*
*/
@Repository
public class CitizenDAOImpl extends BaseDAO<Citizen, Long> implements CitizenDAO {
}
我所做的只是重写将调用超类的 removeById。 稍后我打算添加一些加密功能,所以 id 都会被打乱。
package sample.googlecode.genericdao.oldworld.dao;
import org.springframework.stereotype.Repository;
import sample.googlecode.genericdao.oldworld.model.Citizen;
/**
* <p>
* This is the implementation of the Citizen DAO. You can see that we don't
* actually have to implement anything, it is all inherited from GenericDAOImpl
* through BaseDAO. We just specify the entity type (Citizen) and its identifier
* type (Long).
*
* <p>
* The @Repository allows Spring to recognize this as a managed component (so we
* don't need to specify it in XML) and also tells spring to do DAO exception
* translation to the Spring exception hierarchy.
*
* @author dwolverton
*
*/
@Repository
public class CitizenDAOImpl extends BaseDAO<Citizen, Long> implements CitizenDAO {
@Override
public boolean removeById(java.io.Serializable id) {
return super.removeById(id);
}
}
当我运行 mvn clean install 时出现错误
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.
1:compile (default-compile) on project hibernate-maven-web: Compilation failure
[ERROR] /C:/Dev/spike/hibernate-maven-web/src/main/java/sample/googlecode/generi
cdao/oldworld/dao/CitizenDAOImpl.java:[26,24] name clash: removeById(java.io.Ser
ializable) in sample.googlecode.genericdao.oldworld.dao.CitizenDAOImpl and remov
eById(ID) in com.googlecode.genericdao.dao.hibernate.GenericDAO have the same er
asure, yet neither overrides the other
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e swit
ch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please rea
d the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureExc
eption
我知道它的模糊调用以及 BaseDAO 和 CitizenDAO 在某些时候确实继承了 GenericADO。 在这种情况下有什么好的解决方案? 谢谢
【问题讨论】:
标签: java hibernate maven orm dao