开发者

Spring/Hibernate/Flex = Unknown Entity

I am having a bit of trouble with spring+hibernate throwing the error

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.

@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.

@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)

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.persistenc开发者_StackOverflowe.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
}


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. For e.g. if you are using AnnotationSessionFactoryBean from Spring, you would need to include the "packagesToScan" property to indicate which packages should be scanned.

If this is already done, can you attach the spring configuration files related to Hibernate?


Have you included the UserAccount in your persistence.xml? That's usually the first place i look.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜