Hibernate错误 - 小问题但非常重要

时间:2011-10-10 16:21:48

标签: hibernate exception

以下是我的.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]

知道为什么吗?缺少什么?

2 个答案:

答案 0 :(得分:1)

我怀疑你在这里有错误的声明class="mmm.UserRatingId"。你是说class="com.mmm.data.UserRatingId"吗? (更正了标识符类的包名称)

答案 1 :(得分:0)

您好我曾经遇到过相同的错误,原因是安全性不允许Domino JVM实例化某些类。

这是我的java.policy,你可以在jvm \ lib \ security \ java.policy文件中找到它以供参考:

// Standard extensions get all permissions by default
grant codeBase "file:${java.home}/lib/ext/*" {
permission java.security.AllPermission;
};

// default permissions granted to all domains
grant { 
// Allows any thread to stop itself using the java.lang.Thread.stop()
// method that takes no argument.
// Note that this permission is granted by default only to remain
// backwards compatible.
// It is strongly recommended that you either remove this permission
// from this policy file or further restrict it to code sources
// that you specify, because Thread.stop() is potentially unsafe.
// See "http://java.sun.com/notes" for more information.
permission java.lang.RuntimePermission "stopThread";

//允许任何人监听非特权端口    权限java.net.SocketPermission“localhost:1024-”,“listen”;

//任何人都可以阅读的“标准”属性

permission java.util.PropertyPermission "java.version", "read";
permission java.util.PropertyPermission "java.vendor", "read";
permission java.util.PropertyPermission "java.vendor.url", "read";
permission java.util.PropertyPermission "java.class.version", "read";
permission java.util.PropertyPermission "os.name", "read";
permission java.util.PropertyPermission "os.version", "read";
permission java.util.PropertyPermission "os.arch", "read";
permission java.util.PropertyPermission "file.separator", "read";
permission java.util.PropertyPermission "path.separator", "read";
permission java.util.PropertyPermission "line.separator", "read";

permission java.util.PropertyPermission "java.specification.version", "read";
permission java.util.PropertyPermission "java.specification.vendor", "read";
permission java.util.PropertyPermission "java.specification.name", "read";

permission java.util.PropertyPermission "java.vm.specification.version", "read";
permission java.util.PropertyPermission "java.vm.specification.vendor", "read";
permission java.util.PropertyPermission "java.vm.specification.name", "read";
permission java.util.PropertyPermission "java.vm.version", "read";
permission java.util.PropertyPermission "java.vm.vendor", "read";
permission java.util.PropertyPermission "java.vm.name", "read";

permission java.util.PropertyPermission "javax.realtime.version", "read";
permission java.security.AllPermission;

};

// Notes java code gets all permissions

grant codeBase "file:${notes.binary}/*" {
permission java.security.AllPermission;
};

grant codeBase "file:${notes.binary}/rjext/*" {
permission java.security.AllPermission;
};

grant codeBase "file:${notes.binary}/ndext/*" {
permission java.security.AllPermission;
};

grant codeBase "file:${notes.binary}/xsp/-" {
permission java.security.AllPermission;
};

grant codeBase "file:${notes.binary}/osgi/-" {
permission java.security.AllPermission;
};