Bonjour,
J'ai une erreur a l’exécution d'une requête nommée. Voici les classes a priori concernees:
Lorsque j'execute ce code:Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129 @Entity @Table(name = "TN_TYPE") @NamedQueries({ @NamedQuery( name = "TNType.findPubIdTn", query = "from TNType") }) public class TNType extends PubIdType implements Serializable { @Column(nullable=false) private String tn; @Embedded private CORInfoType corInfo; @ElementCollection private List<RteRecRefType> rrRef; public TNType() { } public TNType(String rant, DestGrpType dg, String tn, CORInfoType corInfo, List<RteRecRefType> rrRef) { super(rant, dg); this.tn = tn; this.corInfo = corInfo; this.rrRef = rrRef; } /** * @return the tn */ public String getTn() { return tn; } /** * @return the corInfo */ public CORInfoType getCorInfo() { return corInfo; } /** * @return the rrRef */ public List<RteRecRefType> getRrRef() { return rrRef; } /** * @param corInfo the corInfo to set */ public void setCorInfo(CORInfoType corInfo) { this.corInfo = corInfo; } /** * @param rrRef the rrRef to set */ public void setRrRef(List<RteRecRefType> rrRef) { this.rrRef = rrRef; } } @Embeddable public class CORInfoType implements Serializable { private boolean corClaim; private boolean cor; @Temporal(TemporalType.TIMESTAMP) private Date corDate; public CORInfoType() { } public CORInfoType(boolean corClaim, boolean cor, Date corDate) { this.corClaim = corClaim; this.cor = cor; this.corDate = corDate; } /** * @return the corClaim */ public boolean isCorClaim() { return corClaim; } /** * @return the cor */ public boolean isCor() { return cor; } /** * @return the corDate */ public Date getCorDate() { return corDate; } /** * @param corClaim the corClaim to set */ public void setCorClaim(boolean corClaim) { this.corClaim = corClaim; } /** * @param cor the cor to set */ public void setCor(boolean cor) { this.cor = cor; } /** * @param corDate the corDate to set */ public void setCorDate(Date corDate) { this.corDate = corDate; } }
J'obtiens une erreur:Code:
1
2
3 Query query = em.createNamedQuery("TNType.findPubIdTn"); List<TNType> result = query.getResultList();
J'utilise Hibernate et MySQL.Citation:
Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1214)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1147)
at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:255)
at DataAccess.DataAccess.getPubIdTN(DataAccess.java:219)
at DataAccess.DataAccess.createPubIdTN(DataAccess.java:257)
at TestClass.main(TestClass.java:27)
Caused by: org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:92)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.loader.Loader.doList(Loader.java:2536)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276)
at org.hibernate.loader.Loader.list(Loader.java:2271)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:452)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:363)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1268)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:246)
... 3 more
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'tntype0_.cor' in 'field list'
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:407)
at com.mysql.jdbc.Util.getInstance(Util.java:382)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1052)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3603)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3535)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1989)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2150)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2626)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2119)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2281)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1953)
at org.hibernate.loader.Loader.doQuery(Loader.java:802)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274)
at org.hibernate.loader.Loader.doList(Loader.java:2533)
... 11 more
Java Result: 1
Merci d'avance