理由はわかりませんが、データベースからソートされたデータを抽出するメソッドに複数のパラメーターを指定しようとすると、毎回例外に直面します。私がやりたいことは、基準を持つクエリを使用して、あるエンティティと別のエンティティからデータを抽出することです。
エラーは次のように発生します。
INFO : org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [app-context.xml]
INFO : org.springframework.context.annotation.ClassPathBeanDefinitionScanner - JSR-330 'javax.inject.Named' annotation found and supported for component scanning
INFO : org.springframework.context.support.GenericXmlApplicationContext - Refreshing org.springframework.context.support.GenericXmlApplicationContext@1fdc6f6: startup date [Wed May 22 11:06:19 EDT 2013]; root of context hierarchy
INFO : org.springframework.beans.factory.config.PropertyPlaceholderConfigurer - Loading properties file from class path resource [connection.properties]
INFO : org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor - JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
INFO : org.springframework.beans.factory.support.DefaultListableBeanFactory - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@3b8d23: defining beans [dataSource,transactionManager,org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#0,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,daoInsertDataInterface,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,sessionFactory,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor]; root of factory hierarchy
Hibernate: select this_.DATE_ID as DATE1_1_1_, this_.CHILD_ADMISSION_DATE as CHILD2_1_1_, this_.CHILD_GO_SCHOOL_DATE as CHILD3_1_1_, this_.PARTICULAR_DATE as PARTICULAR4_1_1_, this_.VERSION as VERSION1_1_, schedulero2_.DATE_ID as DATE1_1_3_, schedulero3_.SRC_ID as SRC2_3_, schedulero3_.SRC_ID as SRC1_2_0_, schedulero3_.CHILD_ADMITTED as CHILD2_2_0_, schedulero3_.CHILD_GO_SCHOOL as CHILD3_2_0_, schedulero3_.CHILD_UNDER_3_YEARSOLD as CHILD4_2_0_, schedulero3_.CHILD_UPPER_3_YEARSOLD as CHILD5_2_0_, schedulero3_.DAY_SCHEDULE as DAY6_2_0_, schedulero3_.NUMBER_OF_CHILD as NUMBER7_2_0_, schedulero3_.ROTATION as ROTATION2_0_, schedulero3_.VERSION as VERSION2_0_, schedulero3_.WORK_SCHEDULE as WORK10_2_0_ from CREATION_DATE this_ left outer join SRC_DATE schedulero2_ on this_.DATE_ID=schedulero2_.DATE_ID left outer join SCHEDULE_ROTATION_CHILD schedulero3_ on schedulero2_.SRC_ID=schedulero3_.SRC_ID where (this_.PARTICULAR_DATE=? and this_.DATE_ID=?)
WARN : org.hibernate.util.JDBCExceptionReporter - SQL Error: 0, SQLState: 07001
ERROR: org.hibernate.util.JDBCExceptionReporter - No value specified for parameter 2
Exception in thread "main" 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:2545)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276)
at org.hibernate.loader.Loader.list(Loader.java:2271)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:119)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1716)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:347)
at edu.demidov.dao.InsertDataService.findByDateAndType(InsertDataService.java:82)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:96)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at $Proxy24.findByDateAndType(Unknown Source)
at edu.demidov.dao.AppTEst.main(AppTEst.java:122)
Caused by: java.sql.SQLException: No value specified for parameter 2
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1078)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:975)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:920)
at com.mysql.jdbc.PreparedStatement.checkAllParametersSet(PreparedStatement.java:2611)
at com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:2586)
at com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:2510)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2259)
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:2542)
... 20 more
私のDAOメソッド:
@Override
public List<CreationDate> findByDateAndType() throws HibernateException, ParseException {
Criterion bydate = Restrictions.eq("particularDate", AppTEst.addMyDate("2003-05-25"));
Criterion byname = Restrictions.eq("institution", new Institution().getTypeName()== "Education");
return sessionFactory.getCurrentSession().createCriteria(CreationDate.class)
.add(Restrictions.and(bydate, byname)).list();
}
私のエンティティ1:
@Entity
@Table(name="CREATION_DATE")
@NamedQueries ({
@NamedQuery(name="creationDate.findById", query="select distinct c from CreationDate c left join fetch c.institution n " +
"left join fetch c.scheduleRotationChild s where c.dateId= :i"),
@NamedQuery(name="creationDate.findByDate", query="select distinct c from CreationDate c left join fetch c.institution i" +
"left join fetch c.scheduleRotationChild s where c.particularDate= :date"),
@NamedQuery(name="creationDate.findAll", query="select distinct c from CreationDate c left join fetch c.institution n " +
"left join fetch c.scheduleRotationChild s ")
})
public class CreationDate implements Serializable {
private static final long serialVersionUID = 1648102358397071136L;
private int dateId;
@Id
@GeneratedValue(strategy=IDENTITY)
@Column(name="DATE_ID")
public int getDateId() {
return dateId;
}
public void setDateId(int dateId) {
this.dateId = dateId;
}
private Date particularDate;
@Column(name="PARTICULAR_DATE")
public Date getParticularDate() {
return particularDate;
}
public void setParticularDate(Date particularDate) {
this.particularDate = particularDate;
}
private int version;
@Version
@Column(name="VERSION")
public int getVersion() {
return version;
}
public void setVersion(int version) {
this.version = version;
}
private Date childGoSchoolDate;
@Temporal(TemporalType.DATE)
@Column(name="CHILD_GO_SCHOOL_DATE")
public Date getChildGoSchoolDate() {
return childGoSchoolDate;
}
public void setChildGoSchoolDate(Date childGoSchoolDate) {
this.childGoSchoolDate = childGoSchoolDate;
}
private Date childAdmissionDate;
@Temporal(TemporalType.DATE)
@Column(name="CHILD_ADMISSION_DATE")
public Date getChildAdmissionDate() {
return childAdmissionDate;
}
public void setChildAdmissionDate(Date childAdmissionDate) {
this.childAdmissionDate = childAdmissionDate;
}
private Set<Institution> institution = new HashSet<Institution>();
@ManyToMany(fetch = FetchType.LAZY)
@Cascade(org.hibernate.annotations.CascadeType.ALL)
@JoinTable(name="CREATIONDATE_INSTITUTION",
joinColumns=@JoinColumn(name="DATE_ID"),
inverseJoinColumns=@JoinColumn(name="INSTITUTION_ID"))
public Set<Institution> getInstitution() {
return institution;
}
public void setInstitution(Set<Institution> institutionSet) {
this.institution = institutionSet;
}
private List<ScheduleRotationChild> scheduleRotationChild = new ArrayList<ScheduleRotationChild>();
@OneToMany(fetch=FetchType.EAGER, orphanRemoval=true)
@Cascade(org.hibernate.annotations.CascadeType.ALL)
@JoinTable(name="SRC_DATE",
joinColumns=@JoinColumn(name="DATE_ID"),
inverseJoinColumns=@JoinColumn(name="SRC_ID"))
public List<ScheduleRotationChild> getScheduleRotationChild() {
return scheduleRotationChild;
}
public void setScheduleRotationChild(
List<ScheduleRotationChild> scheduleRotationChild) {
this.scheduleRotationChild = scheduleRotationChild;
}
public void addNameInstitution(Set<Institution> institution) {
setInstitution(institution);
}
public void addSRC(List<ScheduleRotationChild> srcinstitution) {
setScheduleRotationChild(srcinstitution);
}
public String toString() {
return dateId + " , "
+ particularDate + " , "
+ childGoSchoolDate + " , "
+ childAdmissionDate + " " + scheduleRotationChild ;
}
}
私のエンティティ2:
@Entity
@Table(name="INSTITUTION")
@NamedQuery(name="creationDate.findByName", query="select distinct i from Institution i left join fetch i.creationDate c " +
"where i.institutionId= :i")
public class Institution implements Serializable{
private static final long serialVersionUID = -7636394097858726922L;
private int institutionId;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="INSTITUTION_ID")
public int getInstitutionId() {
return institutionId;
}
public void setInstitutionId(int institutionId) {
this.institutionId = institutionId;
}
private int version;
@Version
@Column(name="VERSION")
public int getVersion() {
return version;
}
public void setVersion(int version) {
this.version = version;
}
private String nameOfInstitution;
@Column(name="NAME_INSTITUTION")
public String getNameOfInstitution() {
return nameOfInstitution;
}
public void setNameOfInstitution(String nameOfInstitution) {
this.nameOfInstitution = nameOfInstitution;
}
private String typeName;
@Column(name="TYPE_NAME")
public String getTypeName() {
return typeName;
}
public void setTypeName(String typeName) {
this.typeName = typeName;
}
private Set<CreationDate> creationDate = new HashSet<CreationDate>();
@ManyToMany(mappedBy="institution", fetch = FetchType.LAZY)
@Cascade(org.hibernate.annotations.CascadeType.ALL)
public Set<CreationDate> getCreationDate() {
return creationDate;
}
public void setCreationDate(
Set<CreationDate> creationDateSet) {
this.creationDate = creationDateSet;
}
public void addCreationDate(CreationDate cDate, Set<CreationDate> crDate, List<ScheduleRotationChild> src) {
cDate.setScheduleRotationChild(src);
setCreationDate(crDate);
}
public String toString() {
return institutionId + " , " + nameOfInstitution + " , " + typeName ;
}
}
助けてください。ありがとうございました。