开发者

Hibernate error - small issue but very important

Following is my .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>

Here is the 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开发者_StackOverflow社区 = 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;
    }
}

When I do "from UserRating ur where ur.recipeId = :recipeId and rr.userId= :userId"; get: Initial SessionFactory creation failed.org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.tuple.component.PojoComponentTuplizer]

Any idea why? What is missing?


I suspect you have a wrong declaration here class="mmm.UserRatingId". Did you mean class="com.mmm.data.UserRatingId" ? (corrected package name for the Identifier class)


Hi I once had the same error and the reason was with security that does not let the Domino JVM instantiate some classes.

Here is my java.policy which you can find in jvm\lib\security\java.policy file for reference:

// 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";

// allows anyone to listen on un-privileged ports permission java.net.SocketPermission "localhost:1024-", "listen";

// "standard" properies that can be read by anyone

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;
};
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜