gpt4 book ai didi

java - hibernate 5.2 : how to map set of enums by name using hbm file

转载 作者:行者123 更新时间:2023-11-30 10:13:40 25 4
gpt4 key购买 nike

我正在寻找通过 hbm 文件映射枚举的解决方案(或文档),但我只找到带有注释的解决方案。我想知道是否可以使用 hbm 文件。

这是我的 hbm 文件。

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">

<hibernate-mapping default-access="field">
<typedef name="CantonEnum" class="org.hibernate.type.EnumType">
<param name="enumClass">ch.globaz.avs.affiliation.domaine.commun.valuetype.Canton</param>
<param name="useNamed">true</param>
</typedef>
<class name="ch.globaz.avs.affiliation.domaine.assurance.valuetype.Caisse" table="CAISSE">

<id name="id" column="ID" type="java.lang.Long">
<generator class="org.hibernate.id.IdentityGenerator"/>
</id>

<property name="numeroFederaleCaisse" column="NUMERO_FEDERALE_CAISSE" type="java.lang.String"/>

<property name="numeroInterneCaisse" column="NUMERO_INTENRE_CAISSE" type="java.lang.String"/>

<property name="genreAssurance" column="GENRE_ASSURANCE">
<type name="org.hibernate.type.EnumType">
<param name="enumClass">ch.globaz.avs.affiliation.domaine.assurance.valuetype.CaisseType</param>
<param name="useNamed">true</param>
</type>
</property>
<property name="designation" column="DESIGNATGION" type="java.lang.String"/>
<property name="position" column="POSITION" type="java.lang.Long"/>

<set name="cantons" table="CAISSE_CANTON">
<key column="FK_CAISSE" not-null="true"/>
<element
column="canton"
type="CantonEnum"
not-null="true"
/>
</set>

<list name="codesNogas" cascade="all">
<key column="FK_CAISSE"/>
<index column="IDX_CAISSE_CODENOGACAISSE"/>
<one-to-many class="ch.globaz.avs.affiliation.domaine.assurance.valuetype.CodeNogaCaisse"/>
</list>
</class>

但是我有这个异常(exception):

    Caused by: org.h2.jdbc.JdbcSQLException: Erreur de syntaxe dans linstruction SQL {0}; attendu {1}
Syntax error in SQL statement {0}; expected {1}; SQL statement:
select caisse0_.ID as ID1_6_, caisse0_.NUMERO_FEDERALE_CAISSE as NUMERO_F2_6_, caisse0_.NUMERO_INTENRE_CAISSE as NUMERO_I3_6_, caisse0_.GENRE_ASSURANCE as GENRE_AS4_6_, caisse0_.DESIGNATGION as DESIGNAT5_6_, caisse0_.POSITION as POSITION6_6_ from CAISSE caisse0_ inner join CODE_NOGA_CAISSE codesnogas1_ on caisse0_.ID=codesnogas1_.FK_CAISSE cross join CAISSE_CANTON cantons2_ where caisse0_.ID=cantons2_.FK_CAISSE and .=? and caisse0_.GENRE_ASSURANCE=? and (codesnogas1_.CODE in (?)) [42001-197]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:357)
at org.h2.message.DbException.getSyntaxError(DbException.java:217)
at org.h2.command.Parser.getSyntaxError(Parser.java:555)
at org.h2.command.Parser.readTerm(Parser.java:3078)
at org.h2.command.Parser.readFactor(Parser.java:2587)
at org.h2.command.Parser.readSum(Parser.java:2574)
at org.h2.command.Parser.readConcat(Parser.java:2544)
at org.h2.command.Parser.readCondition(Parser.java:2370)
at org.h2.command.Parser.readAnd(Parser.java:2344)
at org.h2.command.Parser.readExpression(Parser.java:2334)
at org.h2.command.Parser.parseSelectSimple(Parser.java:2291)
at org.h2.command.Parser.parseSelectSub(Parser.java:2133)
at org.h2.command.Parser.parseSelectUnion(Parser.java:1946)
at org.h2.command.Parser.parseSelect(Parser.java:1919)
at org.h2.command.Parser.parsePrepared(Parser.java:463)
at org.h2.command.Parser.parse(Parser.java:335)
at org.h2.command.Parser.parse(Parser.java:311)
at org.h2.command.Parser.prepareCommand(Parser.java:278)
at org.h2.engine.Session.prepareLocal(Session.java:611)
at org.h2.engine.Session.prepareCommand(Session.java:549)
at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1247)
at org.h2.jdbc.JdbcPreparedStatement.<init>(JdbcPreparedStatement.java:76)
at org.h2.jdbc.JdbcConnection.prepareStatement(JdbcConnection.java:304)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.tomcat.jdbc.pool.ProxyConnection.invoke(ProxyConnection.java:126)
at org.apache.tomcat.jdbc.pool.JdbcInterceptor.invoke(JdbcInterceptor.java:108)
at org.apache.tomcat.jdbc.pool.interceptor.AbstractCreateStatementInterceptor.invoke(AbstractCreateStatementInterceptor.java:75)
at org.apache.tomcat.jdbc.pool.JdbcInterceptor.invoke(JdbcInterceptor.java:108)
at org.apache.tomcat.jdbc.pool.DisposableConnectionFacade.invoke(DisposableConnectionFacade.java:81)
at com.sun.proxy.$Proxy67.prepareStatement(Unknown Source)
at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$5.doPrepare(StatementPreparerImpl.java:146)
at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:172)
... 74 more

我找到了这个解决方案,但它似乎不起作用:Hibernate 3.3: how to map list of enums by name

最佳答案

我意识到异常来 self 们忘记添加连接的 criteriabuilder (Join cantonJoin = root.join("cantons");) 现在 sql 是正确的。

映射完全正确。

关于java - hibernate 5.2 : how to map set of enums by name using hbm file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51240708/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com