Spring Boot启动 Unable to build Hibernate SessionFactory; nested exception is org.hibernate.MappingException: Could not instantiate id generator错误

时间:2024-01-14 09:17:14
开始运行得很好的项目,因为前一天高度了项目结构和名称突然报上面的错误 查了很多网上资料很多解决方案

造成这个错误的原因有很多,例如

1、@Entity 类有变动,无非正常生成对应的数据库。 
解决:使用 spring: jpa: hibernate:ddl-auto: create 删除之前的数据库,重新重建数据库

2、变量的类型不对,例如:使用list的变量,就会出现这个错误

3、使用多个@Id注解的方式不正确。 
解决:如何使用联合主键(复合主键)

4、@Column(name)的注解与数据库字段不匹配。 
解决:参考这里
--------------------- 
作者:薛瑄 
来源:CSDN 
原文:https://blog.csdn.net/xx326664162/article/details/79459114 
版权声明:本文为博主原创文章,转载请附上博文链接!

始终没解决问题 最后发现下面这个提示,看来和自定义主键有关
Spring Boot启动 Unable to build Hibernate SessionFactory; nested exception is org.hibernate.MappingException: Could not instantiate id generator错误aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAukAAABHCAYAAAC6Tdm8AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAABaFSURBVHhe7Z37bxzXdcfz98TiQxDfICWKpEBRFElRliiJJPimSFVuZMBS/agtv2TLst2icNE6KYLUTeumqNs0BdIH2vQBp0XdB5o6qA3bUN1Wfgp9pGni2E5b3N7vmHc9Gt87O7PcXc5yPz8suJq9e+fccz/3zvecObP63G233Waa/fXHJ283lwYPRH54ZHjI3FheMB+fO2veXJo3FwYGmt4/zc4H42ePgAEYgAEYgAEYqDcDn6v3CYt2vs3+PvP1Y1Mlkf7awqzZ395m9rW0mAcODprvn11FpBPIwQAMwAAMwAAMwAAM1JWBphbpnVaIXx46aH7u8GhJpLsgosN+dr/97JvHp+s6IUULYrCHzAEMwAAMwAAMwAAM1J+BphbpV0aGTduePV6Rbs5vmr85M2O6W1tTRbravTx32ly3pTGvzM+a5ybGS+3ne3rMOytL5l370nsBrvZ6rfT2mrd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EYgIFGYQCRjkjnNhoMwAAMwAAMwAAMwEDBGECkF2xCGiW6w04yETAAAzAAAzAAAzBQOwYQ6Yh0ImcYgAEYgAEYgAEYgIGCMYBIL9iEEJHWLiLFt/gWBmAABmAABmCgURhApCPSiZxhAAZgAAZgAAZgAAYKxgAivWAT0ijRHXaSiYABGIABGIABGICB2jGASEekEznDAAzAAAzAAAzAAAwUjAFEesEmhIi0dhEpvsW3MAADMAADMAADjcIAIh2RTuQMAzAAAzAAAzAAAzBQMAYQ6QWbkEaJ7rCTTAQMwAAMwAAMwAAM1I4BRDoincgZBmAABmAABmAABmCgYAwg0gs2IUSktYtI8S2+hQEYgAEYgAEYaBQGEOmIdCJnGIABGIABGIABGICBgjGASC/YhDRKdIedZCJgAAZgAAZgAAZgoHYMINIR6UTOMAADMAADMAADMAADBWMAkV6wCSEirV1Eim/xLQzAAAzAAAzAQKMwgEhHpBM5wwAMwAAMwAAMwAAMFIwBRHrBJqRRojvsJBMBAzAAAzAAAzAAA7VjAJGOSCdyhgEYgAEYgAEYgAEYKBgDiPSCTQgRae0iUnyLb2EABmAABmAABhqFAUQ6Ip3IGQZgAAZgAAZgAAZgoGAMINILNiGNEt1hJ5kIGIABGIABGIABGKgdA4h0RDqRMwzAAAzAAAzAAAzAQMEY+H8dCExL+TWeVwAAAABJRU5ErkJggg==" alt="" />
我用了自定义主键策略
 @GeneratedValue(strategy = GenerationType.AUTO, generator = "custom-id")
@GenericGenerator(name = "custom-id", strategy = "CustomIDGenerator")

改成下面的代码后问题解决

 @GeneratedValue(strategy = GenerationType.AUTO, generator = "custom-id")
@GenericGenerator(name = "custom-id", strategy = "com.xxsoft.common.utils.core.CustomIDGenerator")

怀疑是因为自定义策略在公用包里面,因为昨天调整了公用包的名称,中间加了common就出这问题了。终于又踩过一个坑。。。