@Component
@Entity
@Table(name="menu")
@Configurable
public class Menu implements Serializable{
....
@OneToMany(mappedBy="menu", fetch=FetchType.EAGER)
private Set<VoceMenu> voceMenuList;
public Set<VoceMenu> getVoceMenuList() {
return voceMenuList;
}
public void setVoceMenuList(Set<VoceMenu> voceMenuList) {
this.voceMenuList = voceMenuList;
}
.....
}
Run Code Online (Sandbox Code Playgroud)
我打印一个表单来编辑菜单,以及它的相对VoceMenu对象,这样:
<form:form action="editMenu" method="post" commandName="menu">
Menu id<form:input path="id" maxlength="11"/><br/>
......
<c:forEach items="${menu.voceMenuList}" varStatus="counter">
<form:input path="voceMenuList[${counter.index}].id" maxlength="11"/>
.....
</c:forEach>
<input type="submit">
</form:form>
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试保存对象菜单时,我收到此错误:
bean类[com.springgestioneerrori.model.Menu]的属性'voceMenuList [0]'无效:无法从大小为0的集合获取索引为0的元素,使用属性路径'voceMenuList [0]'访问
我开始向您展示我的情况。
这是我的父对象:
@Entity
@Table(name="cart")
public class Cart implements Serializable{
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Id
@Column(name="id")
private Integer id;
@OneToMany(mappedBy="cart", fetch = FetchType.EAGER, cascade = CascadeType.ALL)
private List<CartItem> cartItems;
...
}
Run Code Online (Sandbox Code Playgroud)
这是我的孩子对象:
@Entity
@Table(name="cart_item")
public class CartItem implements Serializable{
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Id
@Column(name="id")
private Integer id;
@ManyToOne
@JoinColumn(name="cart_id", nullable=false)
private Cart cart;
...
}
Run Code Online (Sandbox Code Playgroud)
正如您看到数据库一样,在表cart_item(子对象)中,字段cart_id具有指向表cart(父对象)的字段ID的外键。
这是我保存对象的方式:
1)有一个restController,它读取一个JSON对象:
@RestController
@RequestMapping(value = "rest/cart")
public class CartRestController {
@Autowired
private CartService cartService;
@RequestMapping(method = RequestMethod.POST)
@ResponseStatus(value = HttpStatus.CREATED) …Run Code Online (Sandbox Code Playgroud) 我用Spring Security制作了一个登录系统.这是我的spring-security.xml
...
<session-management invalid-session-url="/login">
<concurrency-control max-sessions="1" expired-url="/login" error-if-maximum-exceeded="true"/>
</session-management>
<form-login
login-page="/login"
default-target-url="/index"
always-use-default-target="true"
authentication-failure-url="/login?error=true"
username-parameter="j_username"
password-parameter="j_password" />
<logout
logout-success-url="/login"
delete-cookies="JSESSIONID"
invalidate-session="true" />
...
Run Code Online (Sandbox Code Playgroud)
因为我有这行 authentication-failure-url="/login?error=true"
我知道,如果 error是'true'有一个错误:它可能是" 坏凭据 "或" 最大会话数突破 ".但我想知道哪些错误真的occorred?
有没有办法,在java类(@controller)中,知道Spring给我的错误类型,以便自定义这些错误消息?
我正在尝试使用Hibernate和Spring DataSourceTransactionManager来处理提交和回滚函数,但可能我得不到什么.
在使用Spring DataSourceTransactionManager之前,这是我的DAO类之一
package com.springgestioneerrori.DAO;
public class UtenteDAO extends DAOBase{
public void salvaUtente(Utente utenteIn) throws DAOException{
Session session = getHibernateSession(); //from this method I get Hibernate SessionFactory
try{
session.beginTransaction();
session.saveOrUpdate(Object);
session.getTransaction().commit();
}
catch(Exception e){
session.getTransaction().rollback()
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是给我sessionFactory的类
private static final SessionFactory sessionFactory = buildSessionFactory();
private static SessionFactory buildSessionFactory() {
try {
// Create the SessionFactory from hibernate.cfg.xml
return new AnnotationConfiguration().configure().buildSessionFactory();
}
catch (Throwable ex) {
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public …Run Code Online (Sandbox Code Playgroud) 我为我的网站更改了主机公司,在其中我使用了 mySQL 数据库。我不时收到此错误:
连接关闭后不允许进行任何操作。
我记得我第一次在旧服务器上运行我的网站时遇到了同样的问题,我用“配置修复”而不是“代码修复”解决了这个问题,但我不记得我做了什么:(
我在这里阅读了很多帖子,但每个人都在谈论代码修复,我认为这不是我的情况
有人能帮我吗?
谢谢
编辑
我在旧的 context.xml 文件中找到了这个;可能这就是我解决问题的方式
validationQuery="SELECT 1"
testOnBorrow="true"
Run Code Online (Sandbox Code Playgroud)
testOnBorrow: (boolean) 对象在从池中借用之前是否被验证的指示。如果对象无法验证,它将从池中删除,我们将尝试借用另一个。注意 - 要使真值产生任何效果,validationQuery 参数必须设置为非空字符串。默认值为 false
validationQuery :(String) 将用于在将连接返回给调用者之前验证来自该池的连接的 SQL 查询。如果指定,此查询不必返回任何数据,它只是不能抛出 SQLException。默认值为空。示例值为 SELECT 1(mysql), select 1 from dual(oracle), SELECT 1(MS Sql Server)
有人可以确认吗?
可能这是一个非常愚蠢的问题,但我在互联网上找不到任何东西.
写作<mvc:mapping path="/**"/>和<mvc:mapping path="/*"/>Spring 之间有什么区别?
我有一个方法,它接受所有扩展Persona.Class(Uomo.Class和Donna.Class扩展Persona.Class)的类作为参数.
public PersonaDecorator(Class <? extends Persona> persona) {
}
Run Code Online (Sandbox Code Playgroud)
在此方法中,我需要知道,如果发送到方法的类Uomo.Class或Donna.Class.
我以为我可以这样做:
public PersonaDecorator(Class <? extends Persona> persona) {
if(persona instanceof Uomo){
......
}
}
Run Code Online (Sandbox Code Playgroud)
但我得到这个错误: Incompatible conditional operand types Class<capture#1-of ? extends Persona> and Uomo
谢谢
我必须动态创建4个按钮,我必须动态生成他们的id,如:
for(int i = 1; i <= 4; i++){
Button button = new Button(activity);
// i need something here to turn this string into an int;
button.setId("button" + i)
}
Run Code Online (Sandbox Code Playgroud)
我知道如何动态获取现有视图的id:
getResources().getIdentifier("button2", "button", getPackageName())
Run Code Online (Sandbox Code Playgroud)
我不知道的是,如何动态生成id.
我在互联网上看了,但我没有找到任何东西.
我需要这样的东西:
int id = getResources().setIdentifier("button2", "button", getPackageName());
button.setid(id);
Run Code Online (Sandbox Code Playgroud)
先感谢您.
当我尝试ELSE IF在程序中使用a时,我遇到了一个奇怪的错误,我无法理解我做错了什么.我正在用TOAD创建程序.
此代码有效:
CREATE OR REPLACE PROCEDURE findMin(valore1 in integer, valore2 in integer, risultato out integer) IS
BEGIN
IF(valore1 < valore2) THEN
risultato:= valore1;
ELSE
risultato:= valore2;
END IF;
END;
/
Run Code Online (Sandbox Code Playgroud)
事实并非如此.我在最后一行代码中得到此错误:Found: ';' - Expecting IF
CREATE OR REPLACE PROCEDURE findMin(valore1 in integer, valore2 in integer, risultato out integer) IS
BEGIN
IF(valore1 < valore2) THEN
risultato:= valore1;
ELSE IF (valore1 > valore2) THEN
risultato:= valore2;
ELSE
risultato := 0;
END IF;
END; --here I get the error …Run Code Online (Sandbox Code Playgroud) 我读了很多关于该错误的帖子javax/transaction/TransactionManager,但这些解决方案都没有解决我的问题。
首先要说的是,当我在服务器上部署 Web 应用程序(使用 Spring MVC 和 Hibernate 制作)时,我收到了该错误。在我的电脑上,Eclipse 和 Tomcat 7 一切正常。
第二件事要说的是,在该服务器上,我有另一个 Web 应用程序在 tomcat 文件夹下运行/root(这是一个简单的 java 应用程序,既不使用 Spring mvc 也不使用 Hibernate)。我尝试部署的新应用程序正在另一个名为 的文件夹下运行/prova。
另外,根据我在一些帖子中读到的内容,我添加到了我的 lib 文件夹中:
1)jta-3.1.2.2.jar
2)hibernate3.3.1-jta-1.1.jar
3)javax.transaction.jar
在我的 xml 文件中,我有一个定义事务管理器的 bean
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
Run Code Online (Sandbox Code Playgroud)
奇怪的是,在服务器日志中,确切的错误是
Caused by: java.lang.NoClassDefFoundError: Ljavax/transaction/TransactionManager;
Run Code Online (Sandbox Code Playgroud)
前面有个Ljavax/transaction/TransactionManager
任何想法?
谢谢
java ×8
spring ×4
spring-mvc ×4
hibernate ×3
jsp ×2
android ×1
android-view ×1
extends ×1
instanceof ×1
jpa ×1
jstl ×1
many-to-one ×1
mysql ×1
one-to-many ×1
oracle ×1
plsql ×1
spring-form ×1
transactions ×1