控制台打印结果 : from TCzryxx where sn=1 QueryImpl( from TCzryxx where sn=1 ) [null] /////////////////////////////////////// List uesrsList = query.list(); list是[null]为什么?
"from TCzryxx where sn=1 " 改成 "from TCzryxx t where t.sn=1 " 试一下看
"from TCzryxx where sn=1 " 改成 "from TCzryxx t where t.sn=1 " 试一下看 不行 还是一样
当有三条记录时 : /////////////////////////////////////// List uesrsList = query.list(); list是[null, null, null]为什么?
from TCzryxx where sn=1
QueryImpl( from TCzryxx where sn=1 )
[null]
///////////////////////////////////////
List uesrsList = query.list();
list是[null]为什么?
改成 "from TCzryxx t where t.sn=1 "
试一下看
改成 "from TCzryxx t where t.sn=1 "
试一下看
不行 还是一样
///////////////////////////////////////
List uesrsList = query.list();
list是[null, null, null]为什么?
贴出来看下。。
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"><!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration> <session-factory>
<property name="connection.username">sy</property>
<property name="connection.url">jdbc:oracle:thin:@127.0.0.1:1521:server</property>
<property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>
<property name="myeclipse.connection.profile">cmdb</property>
<property name="connection.password">0</property>
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<mapping resource="com/Hibernate/TCzryxx.hbm.xml" /> </session-factory></hibernate-configuration>
/////////////////////////////////////////////////////////////////////////////////
TCzryxx.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse - Hibernate Tools
-->
<hibernate-mapping>
<class name="com.Hibernate.TCzryxx" table="T_CZRYXX" schema="SY">
<composite-id name="id" class="com.Hibernate.TCzryxxId">
<key-property name="sn" type="long">
<column name="SN" precision="22" scale="0" />
</key-property>
<key-property name="VYhmc" type="string">
<column name="V_YHMC" length="42" />
</key-property>
<key-property name="VYhkl" type="string">
<column name="V_YHKL" length="42" />
</key-property>
<key-property name="VYhqx" type="string">
<column name="V_YHQX" length="42" />
</key-property>
<key-property name="VYhxm" type="string">
<column name="V_YHXM" length="42" />
</key-property>
</composite-id>
</class>
</hibernate-mapping>
AbstractTCzryxx.java
public abstract class AbstractTCzryxx implements java.io.Serializable {
// Fields private TCzryxxId id;
// Constructors /** default constructor */
public AbstractTCzryxx() {
}
/** full constructor */
public AbstractTCzryxx(TCzryxxId id) {
this.id = id;
}
// Property accessors public TCzryxxId getId() {
return this.id;
}
public void setId(TCzryxxId id) {
this.id = id;
}
}TCzryxx.java
public class TCzryxx extends AbstractTCzryxx implements java.io.Serializable { // Constructors /** default constructor */
public TCzryxx() {
}
/** full constructor */
public TCzryxx(TCzryxxId id) {
super(id);
}
}TCzryxxId.java
public class TCzryxxId implements java.io.Serializable {
// Fields private long sn;
private String VYhmc;
private String VYhkl;
private String VYhqx;
private String VYhxm;
// Constructors /** default constructor */
public TCzryxxId() {
} /** minimal constructor */
public TCzryxxId(long sn) {
this.sn = sn;
}
// Property accessors public long getSn() {
return this.sn;
}
public void setSn(long sn) {
this.sn = sn;
} public String getVYhmc() {
return this.VYhmc;
}
public void setVYhmc(String VYhmc) {
this.VYhmc = VYhmc;
} public String getVYhkl() {
return this.VYhkl;
}
public void setVYhkl(String VYhkl) {
this.VYhkl = VYhkl;
} public String getVYhqx() {
return this.VYhqx;
}
public void setVYhqx(String VYhqx) {
this.VYhqx = VYhqx;
} public String getVYhxm() {
return this.VYhxm;
}
public void setVYhxm(String VYhxm) {
this.VYhxm = VYhxm;
}
public boolean equals(Object other) {
if ( (this == other ) ) return true;
if ( (other == null ) ) return false;
if ( !(other instanceof TCzryxxId) ) return false;
TCzryxxId castOther = ( TCzryxxId ) other;
return (this.getSn()==castOther.getSn())
&& ( (this.getVYhmc()==castOther.getVYhmc()) || ( this.getVYhmc()!=null && castOther.getVYhmc()!=null && this.getVYhmc().equals(castOther.getVYhmc()) ) )
&& ( (this.getVYhkl()==castOther.getVYhkl()) || ( this.getVYhkl()!=null && castOther.getVYhkl()!=null && this.getVYhkl().equals(castOther.getVYhkl()) ) )
&& ( (this.getVYhqx()==castOther.getVYhqx()) || ( this.getVYhqx()!=null && castOther.getVYhqx()!=null && this.getVYhqx().equals(castOther.getVYhqx()) ) )
&& ( (this.getVYhxm()==castOther.getVYhxm()) || ( this.getVYhxm()!=null && castOther.getVYhxm()!=null && this.getVYhxm().equals(castOther.getVYhxm()) ) );
}
public int hashCode() {
int result = 17;
result = 37 * result + (int) this.getSn();
result = 37 * result + ( getVYhmc() == null ? 0 : this.getVYhmc().hashCode() );
result = 37 * result + ( getVYhkl() == null ? 0 : this.getVYhkl().hashCode() );
result = 37 * result + ( getVYhqx() == null ? 0 : this.getVYhqx().hashCode() );
result = 37 * result + ( getVYhxm() == null ? 0 : this.getVYhxm().hashCode() );
return result;
}
}
中的 id 是复合主键
不能直接通过一个单纯的属性 来导航把。
我初学hibernate