Java 使用SpringMVC应用程序保持打开Hibernate会话
当我试图将模型对象中的集合绑定到表单对象中时,我遇到Java 使用SpringMVC应用程序保持打开Hibernate会话,java,angularjs,rest,spring-mvc,hibernate-session,Java,Angularjs,Rest,Spring Mvc,Hibernate Session,当我试图将模型对象中的集合绑定到表单对象中时,我遇到无效属性异常。我尝试了一些技巧,现在我认为问题在于spring MVC的hibernate会话,因此在控制器中我编辑了create函数,以便在表单保存之前,我尝试获取会话和typesite的列表,但仍然得到相同的错误: org.springframework.beans.InvalidPropertyException: Invalid property ‘siteesTypeSite[idTypeSite]’ of bean class [m
无效属性异常。我尝试了一些技巧,现在我认为问题在于spring MVC的hibernate会话,因此在控制器中我编辑了create函数,以便在表单保存之前,我尝试获取会话和typesite的列表,但仍然得到相同的错误:
org.springframework.beans.InvalidPropertyException: Invalid property ‘siteesTypeSite[idTypeSite]’ of bean class [model.Sites]:
Property referenced in indexed property path ‘siteesTypeSite[idTypeSite]’ is neither an array nor a List nor a Map; returned value was [2]
我的映射有问题吗
Sites.java映射
public class Sites implements java.io.Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
@JsonBackReference("site-typeSite")
@LazyCollection(LazyCollectionOption.FALSE)
@ManyToOne
@JoinColumn(name = “idTypeSite”)
private TypeSites siteesTypeSite;
Getter/setters
}
TypeSites.java映射:
public class TypeSites implements java.io.Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name="idTypeSite")
private int idTypeSite;
private String typeSite;
@LazyCollection(LazyCollectionOption.FALSE)
@JsonManagedReference("site-typeSite")
@OneToMany(mappedBy = “siteesTypeSite”,fetch = FetchType.LAZY)
// private Set<Sites> sitees= new HashSet<Sites>(0);
private List<Sites> sitees = new AutoPopulatingList<Sites>(Sites.class);
Getter/setters
}
JSP:在这里,我调用另一个angular控制器来获取select上的类型site列表
<div ng-controller="siteTypesiteController">
<select required
ng-model="sites.siteesTypeSite"
name="siteesTypeSite"
ng-options="typesites as typesites.typeSite for typesites in page.source "
>
<option value="">-- Select Type site --</option>
</select><br>
问题是:如果我将select的值更改为typesites.typeSite
而不是像这样更改typesites
,则无法提交嵌套对象
<div ng-controller="siteTypesiteController">
<select required
ng-model="sites.siteesTypeSite"
name="siteesTypeSite"
ng-options="typesites.typeSite as typesites.typeSite for typesites in page.source "
>
<option value="">-- Select Type site --</option>
</select><br>
--选择类型站点--
提交工作正常,但我有两个插入:一个插入到typesite
表中,另一个插入到site
表中,使用新的外键。是否启用了hibernate二级缓存?我不知道怎么知道?是否使用XML配置文件?在您的hibernate配置文件中,尝试将这一行添加到您的属性中:trueThank for replay我在我的spring mvc配置中有这一行
是相同的吗?如果你愿意,我会把我所有的配置文件
<div ng-controller="siteTypesiteController">
<select required
ng-model="sites.siteesTypeSite"
name="siteesTypeSite"
ng-options="typesites as typesites.typeSite for typesites in page.source "
>
<option value="">-- Select Type site --</option>
</select><br>
Object {codeOracle: "test", codeGSM: "test", area: "test", siteesTypeSite: Object}
area: "test"
codeGSM: "test"
codeOracle: "test"
siteesTypeSite: Object
idTypeSite: 2
sitees: Array[0]
typeSite: "Public"
__proto__: Object
__proto__: Object
<div ng-controller="siteTypesiteController">
<select required
ng-model="sites.siteesTypeSite"
name="siteesTypeSite"
ng-options="typesites.typeSite as typesites.typeSite for typesites in page.source "
>
<option value="">-- Select Type site --</option>
</select><br>