以下非常重要的是我的.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">
<hibernate-mapping>
<class name="com.mmm.data.UserRating" table="userratings" catalog="mmm">
<composite-id name="id" class="mmm.UserRatingId">
<key-property name="userId" type="int">
<column name="userId" />
</key-property>
<key-property name="recipeId" type="int">
<column name="recipeId" />
</key-property>
</composite-id>
<many-to-one name="recipe" class="com.mmm.data.Recipe" update="false" insert="false" fetch="select">
<column name="recipeId" not-null="true" />
</many-to-one>
<many-to-one name="user" class="com.mmm.data.User" update="false" insert="false" fetch="select">
<column name="userId" not-null="true" />
</many-to-one>
<property name="rating" type="int">
<column name="rating" not-null="true" />
</property>
</class>
</hibernate-mapping>
這裏是Java:
public class UserRating implements java.io.Serializable
{
private UserRatingId id;
private Recipe recipe;
private User user;
private int rating;
/**
*
*/
public UserRating()
{
}
/**
*
* @param id
* @param recipes
* @param users
* @param rating
*/
public UserRating( UserRatingId id,
Recipe recipes,
User users,
int rating)
{
this.id = id;
this.recipe = recipes;
this.user = users;
this.rating = rating;
}
public UserRating( UserRatingId id)
{
this.id = id;
}
/**
*
* @return
*/
public UserRatingId getId()
{
return this.id;
}
/**
*
* @param id
*/
public void setId(UserRatingId id)
{
this.id = id;
}
/**
*
* @return
*/
public Recipe getRecipe()
{
return this.recipe;
}
/**
*
* @param recipe
*/
public void setRecipe(Recipe recipe)
{
this.recipe = recipe;
}
/**
*
* @return
*/
public User getUser()
{
return this.user;
}
/**
*
* @param user
*/
public void setUser(User user)
{
this.user = user;
}
/**
*
* @return
*/
public int getRating()
{
return this.rating;
}
/**
*
* @param rating
*/
public void setRating(int rating)
{
this.rating = rating;
}
}
public class UserRatingId implements java.io.Serializable
{
private int userId;
private int recipeId;
/**
*
*/
public UserRatingId()
{
}
/**
*
* @param userId
* @param recipeId
*/
public UserRatingId( int userId,
int recipeId)
{
this.userId = userId;
this.recipeId = recipeId;
}
/**
*
* @return
*/
public int getUserId()
{
return this.userId;
}
/**
*
* @param userId
*/
public void setUserId(int userId)
{
this.userId = userId;
}
/**
*
* @return
*/
public int getRecipeId()
{
return this.recipeId;
}
/**
*
* @param recipeId
*/
public void setRecipeId(int recipeId)
{
this.recipeId = recipeId;
}
/**
*
*/
public boolean equals(Object other)
{
if ((this == other))
return true;
if ((other == null))
return false;
if (!(other instanceof UserRatingId))
return false;
UserRatingId castOther = (UserRatingId) other;
return (this.getUserId() == castOther.getUserId())
&& (this.getRecipeId() == castOther.getRecipeId());
}
/**
*
*/
public int hashCode()
{
int result = 17;
result = 37 * result + this.getUserId();
result = 37 * result + this.getRecipeId();
return result;
}
}
當我做「從UserRating UR其中ur.recipeId =: recipeId和rr.userId =:userId「; GET:初始SessionFactory的創建failed.org.hibernate.HibernateException:無法創建默認的tuplizer [org.hibernate.tuple.component.PojoComponentTuplizer]
任何想法,爲什麼?什麼不見了?
你可以張貼其它類的定義 – Saket
連接.............. – Yoav