简体   繁体   English

Spring/Hibernate/Flex = 未知实体

[英]Spring/Hibernate/Flex = Unknown Entity

I am having a bit of trouble with spring+hibernate throwing the error我在spring + hibernate抛出错误时遇到了一些麻烦
org.springframework.orm.hibernate3.HibernateSystemException: Unknown entity: com.rottmanj.domain.user.UserAccount; nested exception is org.hibernate.MappingException: Unknown entity: com.rottmanj.domain.user.UserAccount

I have debugged this code and have researched the issue, but it appears that all the normal posted fixes for this issue do not work for me.我已调试此代码并研究了该问题,但似乎针对此问题发布的所有正常修复程序都不适用于我。 Any help with this is greatly appreciated.对此的任何帮助将不胜感激。

I have this dao which should save correctly, but instead throws the error above.我有这个应该正确保存的 dao,但会抛出上面的错误。

@Override
public UserAccount save(UserAccount obj) 
{
    List<UserAccount> userList = template.findByExample(obj);
    try {
        if (!userList.isEmpty()) {
            throw new Exception(
                    "A user with these credentials already exists. Please try again.");
        } else {
            template.saveOrUpdate(obj);
        }
    } catch (Exception e) {
        logger.debug(e.toString());
    }

    return obj;
}

This dao is called by the service below, it is exposed as a remoting destination.这个 dao 被下面的服务调用,它被暴露为一个远程目的地。

@Service
@RemotingDestination(channels = { "my-amf" })
public class UserAccountService {

private UserAccountDAO dao = null;
private static Logger logger = Logger.getLogger(UserAccountService.class);

@Autowired
public void setDao(UserAccountDAO dao)
{
    this.dao = dao;
}

@RemotingInclude
public UserAccount save(UserAccount dataObject)
{
    return this.dao.save(dataObject);
}

@RemotingInclude
public String test(String dataString)
{
    logger.debug(dataString.toString()); 
    return "This is a Test for " + dataString;
}
}

My Entity is annotated so there for it does not use mapping files.我的实体有注释,因此它不使用映射文件。 I have also confirmed that I am using the correct annotation lib (import javax.persistence.Entity)我还确认我使用了正确的注释库(导入 javax.persistence.Entity)

package com.rottmanj.domain.user;

import java.util.HashSet;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

@Entity
@Table(name = "UserAccount", uniqueConstraints = @UniqueConstraint(columnNames =     "UserName"))
public class UserAccount implements java.io.Serializable {
    ...entity cdoe
}

Have you included the UserAccount in your persistence.xml?您是否将 UserAccount 包含在您的 persistence.xml 中? That's usually the first place i look.这通常是我看的第一个地方。

You still have to specify in a spring configuration file or a hibernate mapping file about the existence of this package (or class) so that the scanning can happen.您仍然必须在 spring 配置文件或 hibernate 映射文件中指定此 package(或类)的存在,以便进行扫描。 For eg if you are using AnnotationSessionFactoryBean from Spring, you would need to include the "packagesToScan" property to indicate which packages should be scanned.例如,如果您使用 Spring 中的 AnnotationSessionFactoryBean,则需要包含“packagesToScan”属性以指示应扫描哪些包。

If this is already done, can you attach the spring configuration files related to Hibernate?如果已经完成了,能否附上与Hibernate相关的spring配置文件?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM