-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: In hql,array can't be setted as a parameter?
PostPosted: Thu Sep 09, 2004 12:04 pm 
Newbie

Joined: Tue Aug 17, 2004 4:34 am
Posts: 10
Hibernate version:2.1

Mapping documents:

2 <?xml version="1.0"?>
3 <!DOCTYPE hibernate-mapping PUBLIC
4 "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
5 "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
6
7 <hibernate-mapping>
8 <!--
9 Created by the Middlegen Hibernate plugin 2.1
10
11 http://boss.bekk.no/boss/middlegen/
12 http://www.hibernate.org/
13 -->
14
15 <class
16 name="pam.hibernate.Matgr"
17 table="MATGR"
18 >
19 <meta attribute="class-description" inherit="false">
20 @hibernate.class
21 table="MATGR"
22 </meta>
23
24 <id
25 name="grid"
26 type="java.lang.Long"
27 column="GRID"
28 >
29 <meta attribute="field-description">
30 @hibernate.id
31 generator-class="native"
32 type="java.lang.Long"
33 column="GRID"
34
35
36 </meta>
37 <generator class="assigned" />
38 </id>
39
40 <property
41 name="plantcode"
42 type="java.lang.String"
43 column="PLANTCODE"
44 length="12"
45 >
46 <meta attribute="field-description">
47 @hibernate.property
48 column="PLANTCODE"
49 length="12"
50 </meta>
51 </property>
52 <property
53 name="status"
54 type="java.lang.String"
55 column="STATUS"
56 not-null="true"
57 length="10"
58 >
59 <meta attribute="field-description">
60 @hibernate.property
61 column="STATUS"
62 length="10"
63 not-null="true"
64 </meta>
65 </property>
66 <property
67 name="bodid"
68 type="java.lang.String"
69 column="BODID"
70 length="25"
71 >
72 <meta attribute="field-description">
73 @hibernate.property
74 column="BODID"
75 length="25"
76 </meta>
77 </property>
78 <property
79 name="grdate"
80 type="java.sql.Timestamp"
81 column="GRDATE"
82 length="7"
83 >
84 <meta attribute="field-description">
85 @hibernate.property
86 column="GRDATE"
87 length="7"
88 </meta>
89 </property>
90 <property
91 name="deliid"
92 type="java.lang.String"
93 column="DELIID"
94 length="25"
95 >
96 <meta attribute="field-description">
97 @hibernate.property
98 column="DELIID"
99 length="25"
100 </meta>
101 </property>
102 <property
103 name="delidate"
104 type="java.sql.Timestamp"
105 column="DELIDATE"
106 length="7"
107 >
108 <meta attribute="field-description">
109 @hibernate.property
110 column="DELIDATE"
111 length="7"
112 </meta>
113 </property>
114 <property
115 name="suppliercode"
116 type="java.lang.String"
117 column="SUPPLIERCODE"
118 length="20"
119 >
120 <meta attribute="field-description">
121 @hibernate.property
122 column="SUPPLIERCODE"
123 length="20"
124 </meta>
125 </property>
126 <property
127 name="note"
128 type="java.lang.String"
129 column="NOTE"
130 length="255"
131 >
132 <meta attribute="field-description">
133 @hibernate.property
134 column="NOTE"
135 length="255"
136 </meta>
137 </property>
138 <property
139 name="empid"
140 type="java.lang.String"
141 column="EMPID"
142 length="20"
143 >
144 <meta attribute="field-description">
145 @hibernate.property
146 column="EMPID"
147 length="20"
148 </meta>
149 </property>
150 <property
151 name="deptcode"
152 type="java.lang.String"
153 column="DEPTCODE"
154 length="50"
155 >
156 <meta attribute="field-description">
157 @hibernate.property
158 column="DEPTCODE"
159 length="50"
160 </meta>
161 </property>
162 <property
163 name="crtuser"
164 type="java.lang.String"
165 column="CRTUSER"
166 not-null="true"
167 length="10"
168 >
169 <meta attribute="field-description">
170 @hibernate.property
171 column="CRTUSER"
172 length="10"
173 not-null="true"
174 </meta>
175 </property>
176 <property
177 name="crtdate"
178 type="java.sql.Timestamp"
179 column="CRTDATE"
180 not-null="true"
181 length="7"
182 >
183 <meta attribute="field-description">
184 @hibernate.property
185 column="CRTDATE"
186 length="7"
187 not-null="true"
188 </meta>
189 </property>
190 <property
191 name="upduser"
192 type="java.lang.String"
193 column="UPDUSER"
194 not-null="true"
195 length="10"
196 >
197 <meta attribute="field-description">
198 @hibernate.property
199 column="UPDUSER"
200 length="10"
201 not-null="true"
202 </meta>
203 </property>
204 <property
205 name="upddate"
206 type="java.sql.Timestamp"
207 column="UPDDATE"
208 not-null="true"
209 length="7"
210 >
211 <meta attribute="field-description">
212 @hibernate.property
213 column="UPDDATE"
214 length="7"
215 not-null="true"
216 </meta>
217 </property>
218
219 <!-- Associations -->
220
221 <!-- bi-directional one-to-many association to Matgrsta -->
222 <set
223 name="matgrstas"
224 lazy="true"
225 inverse="true"
226 cascade="none"
227 >
228 <meta attribute="field-description">
229 @hibernate.set
230 lazy="true"
231 inverse="true"
232 cascade="none"
233
234 @hibernate.collection-key
235 column="PRIID"
236
237 @hibernate.collection-one-to-many
238 class="pam.hibernate.Matgrsta"
239 </meta>
240 <key>
241 <column name="PRIID" />
242 </key>
243 <one-to-many
244 class="pam.hibernate.Matgrsta"
245 />
246 </set>
247 <!-- bi-directional one-to-many association to Matgritm -->
248 <set
249 name="matgritms"
250 lazy="true"
251 inverse="true"
252 cascade="none"
253 >
254 <meta attribute="field-description">
255 @hibernate.set
256 lazy="true"
257 inverse="true"
258 cascade="none"
259
260 @hibernate.collection-key
261 column="GRID"
262
263 @hibernate.collection-one-to-many
264 class="pam.hibernate.Matgritm"
265 </meta>
266 <key>
267 <column name="GRID" />
268 </key>
269 <one-to-many
270 class="pam.hibernate.Matgritm"
271 />
272 </set>
273
274 </class>
275 </hibernate-mapping>


Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:
1
2
3 java.lang.IllegalArgumentException: Parameter begin does not exist as a named parameter in [select matgr.deptcode from Matgr matgr where matgr.crtdate>:date[0] and matgr.crtdate<:date[1]]
4
5 at net.sf.hibernate.impl.AbstractQueryImpl.setParameter(AbstractQueryImpl.java:336)
6
7 at net.sf.hibernate.impl.AbstractQueryImpl.setDate(AbstractQueryImpl.java:285)
8
9 at pam.mytry.main(mytry.java:56)
10
11 Exception in thread "main"



Name and version of the database you are using:
oracle 9i


Debug level Hibernate log excerpt:

it's ok like this:
Code:

2  Date begin=cal1.getTime();
3  Date end=cal2.getTime();
4  String query_string="select matgr.deptcode from Matgr matgr where matgr.crtdate>:begin and matgr.crtdate<:end";
5  Query q = s.createQuery(query_string);

7 q.setDate("begin",begin);
8  q.setDate("end",end);
9


but i use array to be the query parameter,it's wrong,I don't know why?
Code:
4  Date[] date_double={cal1.getTime(),cal2.getTime()};
5   
6   
7   String query_string="select matgr.deptcode from Matgr matgr where matgr.crtdate>:date_double[0] and matgr.crtdate<:date_double[1]";
8   Query q = s.createQuery(query_string);
9   
10 q.setDate("date_double[0]",date_double[0]);
11  q.setDate("date_double[1]",date_double[1]);


Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 09, 2004 3:09 pm 
Regular
Regular

Joined: Sat May 29, 2004 2:16 pm
Posts: 81
try reading this:
http://forum.hibernate.org/viewtopic.php?t=934108&highlight=

i solved my case changing char[] to String and then i could use

Code:
q.setString("pp", pp);
again


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 09, 2004 9:26 pm 
Newbie

Joined: Tue Aug 17, 2004 4:34 am
Posts: 10
Thanks ,but you don't use array to be a parameter. If I don't use any array ,it's OK !


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 09, 2004 11:00 pm 
Regular
Regular

Joined: Sat May 29, 2004 2:16 pm
Posts: 81
lippi wrote:
Thanks ,but you don't use array to be a parameter. If I don't use any array ,it's OK !

That's my idea: as i cant use an array as a param in my query, and the password was retreived as a char array, i convert this array to a string in a way to solve my prob...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.