首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Movies2actors没有映射- Hibernate有注释

Movies2actors没有映射- Hibernate有注释
EN

Stack Overflow用户
提问于 2016-02-21 09:32:26
回答 1查看 51关注 0票数 0

使用JSF + Spring + Hibernate开发时,我面临一个令人困惑的问题。我试图在HQL中查询:

代码语言:javascript
复制
private static String  HQL_GET_ACTORS      = "SELECT A FROM Actors A, Movies2actors M "
                                                       + "WHERE M.id.movieid = :movieid "
                                                       + "AND A.actorid = M.id.actorid";

但是当它运行时,我有一个错误:

代码语言:javascript
复制
Movies2actors is not mapped [SELECT A FROM com.ml.model.Actors A, Movies2actors M WHERE M.id.movieid = :movieid AND A.actorid = M.id.actorid]

以下是Hibernate生成的Movies2actors类:

代码语言:javascript
复制
package com.ml.model;
// Generated 13 f�vr. 2016 17:52:31 by Hibernate Tools 4.3.1.Final

import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.Table;

/**
 * Movies2actors generated by hbm2java
 */
@Entity
@Table( name = "movies2actors", catalog = "jmdb" )
public class Movies2actors implements java.io.Serializable {

    private Movies2actorsId id;

    public Movies2actors() {
    }

    public Movies2actors( Movies2actorsId id ) {
        this.id = id;
    }

    @EmbeddedId

    @AttributeOverrides( {
            @AttributeOverride( name = "movieid", column = @Column( name = "movieid", nullable = false ) ),
            @AttributeOverride( name = "actorid", column = @Column( name = "actorid", nullable = false ) ),
            @AttributeOverride( name = "asCharacter", column = @Column( name = "as_character", length = 1000 ) ) })
    public Movies2actorsId getId() {
        return this.id;
    }

    public void setId( Movies2actorsId id ) {
        this.id = id;
    }

}

以及应用程序-context.xml:

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
        <property name="url" value="jdbc:mysql://localhost:3306/jmdb"/>
        <property name="username" value="john"/>
        <property name="password" value="is11seapol"/>
    </bean>

    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="annotatedClasses">
            <list>
                <value>com.ml.model.Movies</value>
                <value>com.ml.model.Actors</value>
                <value>com.ml.model.Directors</value>
                <value>com.ml.model.RatingsId</value>
                <value>com.ml.model.Users</value>
                <value>com.ml.model.Posters</value>
                <value>com.ml.model.Movies2actors</value>
            </list>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</prop>
            </props>
        </property>
    </bean>

    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory"/>
    </bean>

    <tx:annotation-driven transaction-manager="transactionManager"/>

    <context:annotation-config />
    <context:component-scan base-package="com.ml.service"/>
</beans>

奇怪的是,我已经使用一个名为Ratings的表进行了一个HQL查询,它的结构与Movies2actors相同,而且一切都进行得很顺利。

有人知道问题出在哪里吗?

谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-02-21 09:44:52

在您的示例中,您应该在查询中使用完全限定的名称,就像对Actors一样,所以com.ml.model.Movies2actors

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35534467

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档