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 717481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:25:03+00:00 2026-05-14T05:25:03+00:00

I mapped some classes to some tables with hibernate in Java, i set Hibernate

  • 0

I mapped some classes to some tables with hibernate in Java, i set Hibernate to show SQL, it opens the session, it shows that it does the SQL, it closes the session but there are no modifications to the database.

Entity

public class Profesor implements Comparable<Profesor> {
private int id;
private String nume;
private String prenume;
private int departament_id;
private Set<Disciplina> listaDiscipline; //the teacher gives some courses}

public class Disciplina implements Comparable<Disciplina>{ //the course class

private int id;
private String denumire;
private String syllabus;
private String schNotare;
private Set<Lectie> lectii;
private Set<Tema> listaTeme;
private Set<Grup> listaGrupuri; // the course gets teached/assigmened to some groups of students
private Set<Assignment> listAssignments;}

Mapping

<hibernate-mapping default-cascade="all">
<class name="model.Profesor" table="devgar_scoala.profesori">
<id name="id" column="id">
 <generator class="increment"/>
</id>
<set name="listaDiscipline" table="devgar_scoala.`profesori-discipline`">
<key column="Profesori_id" />
<many-to-many class="model.Disciplina" column="Discipline_id"  />
</set>
<property name="nume" column="Nume" type="string" />
<property name="prenume" column="Prenume" type="string" />
<property name="departament_id" column="Departamente_id" type="integer" />
</class>

<class name="model.Grup" table="devgar_scoala.grupe">
<id name="id" unsaved-value="0">
<generator class="increment"/>
</id>
<set name="listaStudenti" table="devgar_scoala.`studenti-grupe`">
<key column="Grupe_id" />
<many-to-many column="Studenti_nrMatricol" class="model.Student" />
</set>

<property name="nume" column="Grupa" type="string"/>
<property name="programStudiu" column="progStudii_id" type="integer" />
</class>
<class name="model.Disciplina" table="devgar_scoala.discipline" >
<id name="id"  >
<generator class="increment"/>
</id> 
<property name="denumire" column="Denumire" type="string"/>
<property name="syllabus" type="string" column="Syllabus"/>
<property name="schNotare" type="string" column="SchemaNotare"/>

<set name="listaGrupuri" table="devgar_scoala.`Discipline-Grupe`">
<key column="Discipline_id" />
<many-to-many column="Grupe_id" class="model.Grup" />
</set>

<set name="lectii" table="devgar_scoala.lectii">
<key column="Discipline_id" not-null="true"/>
<one-to-many class="model.Lectie"  />
</set>
</class>

The only ‘funny’ thing is that the Profesor object gets loaded not with/by Hibernate but with manual classic SQL Java. Thats why i save the Profesor object like this

p – the manually loaded Profesor object

Profesor p2 = (Profesor) session.merge(p);
session.saveOrUpdate(p2);


//flush session of course

After this i get in the Java console:

Hibernate: insert into devgar_scoala.grupe (Grupa, progStudii_id, id) values (?, ?, ?)

but when i look into the database there are no new rows in the table Grupe (the Groups table)

  • 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-05-14T05:25:04+00:00Added an answer on May 14, 2026 at 5:25 am

    As mentioned in the comments, my guess is that you are not committing the changes. You could try something like that:

    Transaction tx = null;
    try {
        tx = session.beginTransaction()
        Profesor p2 = (Profesor) session.merge(p);
        session.saveOrUpdate(p2);
        tx.commit();
    } catch(Exception e) {
        tx.rollback();
    }
    

    You could also use the auto-commit mode in your configuration file to avoid manually committing your changes. Look for the “hibernate.connection.autocommit” property in the Hibernate reference. I don’t think autocommit is supported (well) by all databases though.

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

Sidebar

Ask A Question

Stats

  • Questions 376k
  • Answers 376k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I would add an error function in your setup of… May 14, 2026 at 8:36 pm
  • Editorial Team
    Editorial Team added an answer The signature is likely wrong. Try the following signature: (Ljava/io/File;Lorg/glassfish/api/deployment/DeployCommandParameters;)Ljava/lang/String;… May 14, 2026 at 8:35 pm
  • Editorial Team
    Editorial Team added an answer You want something like: %^((https?://)|(www\.))([a-z0-9-].?)+(:[0-9]+)?(/.*)?$%i this is using the |… May 14, 2026 at 8:35 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.