我在数据库端有两个表(oracle)
create table GROUPS
(
ID NUMBER not null,
GROUP_NAME VARCHAR2(30)
)alter table GROUPS
add constraint ID primary key (ID)
和
create table ITEM_GROUP
(
ITEM_ID VARCHAR2(30) not null,
GROUP_ID NUMBER not null
)
alter table ITEM_GROUP
add constraint ITEM_GROUPD_ID primary key (ITEM_ID, GROUP_ID)
alter table ITEM_GROUP
add constraint ITEM_GROUP_FK01 foreign key (GROUP_ID)
references GROUPS (ID);
比我在Java端有映射类。我想做点什么,当我选择组来取他所有的项目时,我想用hibernate保存项目就是这样。
@Entity
@Table(name = "GROUPS")
public class Group {
@Id
@Column(name = "ID", nullable = false)
@javax.persistence.SequenceGenerator(name = "groupIdGenerator", sequenceName = "GROUP_SEQ", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "groupIdGenerator")
private int id;
@Column(name = "GROUP_NAME")
private String groupName;
@JsonManagedReference
@OneToMany(fetch = FetchType.EAGER, mappedBy="group",cascade = CascadeType.ALL)
private List<GroupItems> groupItems = new ArrayList<>();
// setters and getters
}
@SuppressWarnings("serial")
@Embeddable
public class GroupItemPK implements Serializable {
@Column(name = "ITEM_ID")
private String merchantId;
@Column(name = "GROUP_ID")
private int id;
// getters , setters , constructors , equals hashcode methods
}
@Entity
@Table(name = "ITEM_GROUP")
public class GroupITEM {
@EmbeddedId
private GroupITEMtPK id;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "ID")
@JsonBackReference
private Group group;
}
我感兴趣的是我在构建关系中犯了什么错误吗?如果我做了我的错误,因为我无法做出选择和保存查询而无例外。
我正在尝试使用我的代码
List<Group> list = sessionFactory.getCurrentSession().createQuery("from Group a").list();
这是我的Exception
org.hibernate.engine.jdbc.spi.SqlExceptionHelper could not extract ResultSet [n/a]
java.sql.SQLSyntaxErrorException: ORA-00904: "GROUPITE0_"."ID": invalid identifier