无效的对象名称 - 表名称连接 - 春天

时间:2015-09-01 14:35:59

标签: java sql spring

我在User实体对象

中定义了以下加入列
@Entity(name = "User")
public class User{

    @Id
    @Column(name = "User_Id")
    private long userId;

    @JsonIgnore
    @OneToMany(targetEntity = LookupOrder.class)
    Map<Long, String> orderMap = new LinkedHashMap<Long, String>();

    @ManyToOne
    @JoinColumn(name = "Order_Id", insertable = false, updatable = false)
    private LookupOrder lookupOrder;

    //getters & setters
}

Order.java

@Entity(name = "Lookup_Order")
public class LookupOrder{

    @Id
    @Column(name = "Order_Id")
    private long orderId;

    @Column(name = "Order_Num")
    private String orderNum;

    //getters & setters
}

尝试在@RequestMapping方法

中使用以下Spring Repository方法检索用户
@Transactional
@RequestMapping(value = "/getUser/{id}", method = RequestMethod.GET)
public ModelAndView getUserById(@PathVariable(value="id") Long id,  Model model) {
    User user = userRepo.findOne(id);
    //do stuff
}

但是我的表名似乎被连接并抛出并返回一个SQLException:

java.sql.SQLException: Invalid object name 'User_Lookup_Order'.

有关如何解决此问题的想法或以这种方式翻译对象的原因?

UPDATE :创建删除SQL查询时程序实际上失败了

2015-09-01 14:49:30.808 DEBUG 6868 --- [    http-8080-2] o.h.p.c.AbstractCollectionPersister      : Deleting collection: [com.myapp.entities.User.orderMap#2]
2015-09-01 14:49:30.881 DEBUG 6868 --- [    http-8080-2] org.hibernate.SQL                        : delete from User_Lookup_Order where User_User_Id=?
2015-09-01 14:49:31.026 DEBUG 6868 --- [    http-8080-2] o.h.engine.jdbc.spi.SqlExceptionHelper   : could not execute statement [n/a]

java.sql.SQLException: Invalid object name 'User_Lookup_Order'.

0 个答案:

没有答案