Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7980061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:57:13+00:00 2026-06-04T09:57:13+00:00

I am trying to insert the values from textfields in the database using hibernate

  • 0

I am trying to insert the values from textfields in the database using hibernate and it doesn’t work.
For example I want to insert into the Product table, where I have the following columns:
idproduct, idprovider, idcategory, name, quantity.

    Session session = HibernateUtil.getSessionFactory().openSession();
    org.hibernate.Transaction tx = session.beginTransaction();
    Product product = new Product();
    int idProduct = Integer.parseInt(IdProductTextField.getText());
    product.setIdproduct(idProduct);
    session.save(product);
    tx.commit();

This is the only column that is inserted, because in the set method I have a int parameter.

But all the other columns don’t work. And here is the problem:

All the other set methods for the other columns that I want to insert in the Product table have as parameter a Class variable. For example:

If I want to insert the idprovider, the set method for this is

public void setProduct(Product product) {
    this.product = product;
}

And I really don’t know how to insert the idprovider, using this method.

I have little time and I would appreciate if somebody could help me as quick as possible.

I attach here the Product.java and the Provider.java

package sakila.entity;

import java.util.HashSet;
import java.util.Set;

public class Product  implements java.io.Serializable {

 private int idproduct;
 private Istoricprod istoricprod;
 private Provider provider;
 private Category category;
 private String name;
 private Integer quantity;
 private String unitmas;
 private Set comdetals = new HashSet(0);
 private Set stocs = new HashSet(0);
 private Set bondetals = new HashSet(0);

public Product() {
}


public Product(int idproduct) {
    this.idproduct = idproduct;
}
public Product(int idproduct, Istoricprod istoricprod, Provider provider, Category category, String name, Integer quantity, String unitmas, Set comdetals, Set stocs, Set bondetals) {
   this.idproduct = idproduct;
   this.istoricprod = istoricprod;
   this.provider = provider;
   this.category = category;
   this.name = name;
   this.quantity = quantity;
   this.unitmas = unitmas;
   this.comdetals = comdetals;
   this.stocs = stocs;
   this.bondetals = bondetals;
}

public int getIdproduct() {
    return this.idproduct;
}

public void setIdproduct(int idproduct) {
    this.idproduct = idproduct;
}
public Istoricprod getIstoricprod() {
    return this.istoricprod;
}

public void setIstoricprod(Istoricprod istoricprod) {
    this.istoricprod = istoricprod;
}
public Provider getProvider() {
    return this.furnizor;
}

public void setProvider(Provider provider) {
    this.provider = provider;
}
public Category getCategory() {
    return this.category;
}

public void setCategory(Category category) {
    this.category = category;
}

public String getName() {
    return this.name;
}

public void setName(String name) {
    this.name = name;
}
public Integer getQuantity() {
    return this.quantity;
}

public void setQuantitaty(Integer quantity) {
    this.quantity = quantity;
}
public String getUnitmas() {
    return this.unitmas;
}

public void setUnitmas(String unitmas) {
    this.unitmas = unitmas;
}
public Set getComdetals() {
    return this.comdetals;
}

public void setComdetals(Set comdetals) {
    this.comdetals = comdetals;
}
public Set getStocs() {
    return this.stocs;
}

public void setStocs(Set stocs) {
    this.stocs = stocs;
}
public Set getBondetals() {
    return this.bondetals;
}

public void setBondetals(Set bondetals) {
    this.bondetals = bondetals;
}

}

And the Provider.java is

package sakila.entity;

// Generated Apr 9, 2012 10:19:40 PM by Hibernate Tools 3.2.1.GA

import java.util.HashSet;
import java.util.Set;


public class Provider  implements java.io.Serializable {


 private int idprovider;
 private String denumire;
 private Integer codfiscal;
 private Integer nrfirma;
 private String stradadom;
 private Integer numardom;
 private String orasdom;
 private String judetdom;
 private Integer telefon;
 private Integer codiban;
 private String banca;
 private Set produses = new HashSet(0);
 private Set chitantas = new HashSet(0);
 private Set comandas = new HashSet(0);
 private Set facturas = new HashSet(0);

public Provider() {
}


public Provider(int idprovider) {
    this.idprovider = idprovider;
}
public Provider(int idprovider, String denumire, Integer codfiscal, Integer nrfirma, String stradadom, Integer numardom, String orasdom, String judetdom, Integer telefon, Integer codiban, String banca, Set produses, Set chitantas, Set comandas, Set facturas) {
   this.idprovider = idprovider;
   this.denumire = denumire;
   this.codfiscal = codfiscal;
   this.nrfirma = nrfirma;
   this.stradadom = stradadom;
   this.numardom = numardom;
   this.orasdom = orasdom;
   this.judetdom = judetdom;
   this.telefon = telefon;
   this.codiban = codiban;
   this.banca = banca;
   this.produses = produses;
   this.chitantas = chitantas;
   this.comandas = comandas;
   this.facturas = facturas;
}

public int getIdprovider() {
    return this.idprovider;
}

public void setIdprovider(int idprovider) {
    this.idprovider = idprovider;
}
public String getDenumire() {
    return this.denumire;
}

public void setDenumire(String denumire) {
    this.denumire = denumire;
}
public Integer getCodfiscal() {
    return this.codfiscal;
}

public void setCodfiscal(Integer codfiscal) {
    this.codfiscal = codfiscal;
}
public Integer getNrfirma() {
    return this.nrfirma;
}

public void setNrfirma(Integer nrfirma) {
    this.nrfirma = nrfirma;
}
public String getStradadom() {
    return this.stradadom;
}

public void setStradadom(String stradadom) {
    this.stradadom = stradadom;
}
public Integer getNumardom() {
    return this.numardom;
}

public void setNumardom(Integer numardom) {
    this.numardom = numardom;
}
public String getOrasdom() {
    return this.orasdom;
}

public void setOrasdom(String orasdom) {
    this.orasdom = orasdom;
}
public String getJudetdom() {
    return this.judetdom;
}

public void setJudetdom(String judetdom) {
    this.judetdom = judetdom;
}
public Integer getTelefon() {
    return this.telefon;
}

public void setTelefon(Integer telefon) {
    this.telefon = telefon;
}
public Integer getCodiban() {
    return this.codiban;
}

public void setCodiban(Integer codiban) {
    this.codiban = codiban;
}
public String getBanca() {
    return this.banca;
}

public void setBanca(String banca) {
    this.banca = banca;
}
public Set getProduses() {
    return this.produses;
}

public void setProduses(Set produses) {
    this.produses = produses;
}
public Set getChitantas() {
    return this.chitantas;
}

public void setChitantas(Set chitantas) {
    this.chitantas = chitantas;
}
public Set getComandas() {
    return this.comandas;
}

public void setComandas(Set comandas) {
    this.comandas = comandas;
}
public Set getFacturas() {
    return this.facturas;
}

public void setFacturas(Set facturas) {
    this.facturas = facturas;
}

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T09:57:15+00:00Added an answer on June 4, 2026 at 9:57 am

    Take the provider for example. If you have the provider id of an existing provider, you can do

    • load the provider with the id first
    • set the provider into the product
    • save the product

    example (not complete)

    Provider provider = session.load(provider, idProvider);
    product.setProvider(provider);
    session.save(product);
    

    If you do not want to load the provider first (perhaps superfluous database access), then you can do

    Provider provider = new Provider(idProvider);
    product.setProvider(provider);
    session.save(product);
    

    In this case make sure in the mapping file cascade is set to none; if not also a new provider would be created (if you also want a new provider being created, set cascade=all).

    A third possibility is, in product you do not put a provider object but only the provider id and map it as simple integer. (You even can put both the separate id and the provider object, but that is a bit tricky and generally not recommended.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to insert certain values into the table using SQL server 2005.
I'm trying to insert 10000 values into Oracle from C# and am using the
I am trying to INSERT INTO a table using the input from another table.
I'm trying to insert values from my asp.net application into my MySQL database. On
Possible Duplicate: outputting values from database into html table PHP I am trying to
I'm trying to insert values into a SQL database from within Java. This works
I am trying to insert some values into a database from a form submitted
I am trying to insert the values into cmdmysql.Parameters.Add using values from array. But
I am trying to insert some values into Oracle DB from Java using the
I am trying to insert data from a csv file into mysql using BigDump.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.