There are 2 Entity class Filials
@Entity @NamedQuery(name="allFilials", query="SELECT f FROM Filials f") public class Filials {@Id @GeneratedValue(strategy=GenerationType.IDENTITY) private int id; private String name; private String adress; @OneToMany(mappedBy="filials") private List<Opers> opers; public Filials() { super(); stub } ...
Opers
@Entity @NamedQuery(name = "allOpers", query = "SELECT o FROM Opers o") public class Opers { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private int id; private String name; private String surname; @ManyToOne private Filials filials; public Opers() { super(); // TODO Auto-generated constructor stub } ....
in DAO insert I do
@Override public void insert(Opers oper) { getSession().save(oper); }
insertOper.jsp
<body> <sf:form modelAttribute="opers" action="${pageContext.request.contextPath}/insertOper" method="post"> <table> <tr> <td>Name</td> <td><sf:input path="name" /></td> </tr> <tr> <td>Surname</td> <td><sf:input path="surname" /></td> </tr> <tr> <td></td> <td><input type="submit" value="Save" /></td> </tr> </table> </sf:form>
I need that when insert did, he took and ID Filial. In JSP, when you click on a link, it goes to the Opers page and transfers Filials IDs, but with insert-e this ID cannot be entered into the database. How can I enter it?
getSession().save(oper);
filials
oper
havefilials
? - Sapphironfilials
is, but the value isnull
. And it gets into the database asnull
, then I have to manually enter the value for it in the database and only after that it is correctly displayed. InHibernate: insert into Opers (filials_id, name, surname) values (?, ?, ?)
logsHibernate: insert into Opers (filials_id, name, surname) values (?, ?, ?)
- Farik013@ManyToOne(fetch = FetchType.EAGER)
- Sapphironoper
attribute to the model, then a click to go to a new page, on which data is saved to the database by clicking? The data on the pages change? - Sapphironnull
. I do not know how to enter it into the database. And where should it take value? When you go to theopers.jsp
page, thefilials_id
goes to the URL, but when you go to theinsert.jsp
page, theinsert.jsp
filials_id
not go andinsert.jsp
filials_id
no place to take the value. If you need additional code fragments, you tell me which fragment I will add. - Farik013