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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:29:51+00:00 2026-06-12T09:29:51+00:00

I’m trying to fix a problem with my hibernate db system, but I’m not

  • 0

I’m trying to fix a problem with my hibernate db system, but I’m not sure about what should I doing wrong:

I have two entities: vertex (Vertice) and Tag. One vertice should have many tags. When I add a vertex with Tags in a Set inside, the vertexes are saved into DB, the tags also, but the column FK for vertex is recorded as null. This means that I’m not able to retrieve the set of tags when I need. Thanks for helping!

Beneath are the codes:

import java.util.Set;
public class Vertice {

private long id;
private Set<Tag> tags;
private String amostra = new String();
private String chave = new String();

public Vertice() {
}

public long getId() {
    return id;
}
public void setId(long id) {
    this.id = id;
}
public Set<Tag> getTags() {
    return tags;
}
public void setTags(Set<Tag> tags) {
    this.tags = tags;
}
public String getAmostra() {
    return amostra;
}
public void setAmostra(String amostra) {
    this.amostra = amostra;
}
public String getChave() {
    return chave;
}
public void setChave(String chave) {
    this.chave = this.geraChave(chave);
}

private String geraChave(String chave){
    String _chave = new String();
    _chave = chave;
    try{
        if(this.getTags()!=null){
            for(Tag t: this.getTags()){
                _chave = _chave + t.getTexto();
            }
        }
    }
    catch(Exception e){
        e.printStackTrace();
    }
    return _chave;
}

}

Class Tag:

public class Tag {
    private long id;
    private int linha;
    private int coluna;
    private String texto = new String();

private Vertice vertice;

public Vertice getVertice() {
    return vertice;
}
public void setVertice(Vertice vertice) {
    this.vertice = vertice;
}
public int getLinha() {
    return linha;
}
public int getColuna() {
    return coluna;
}
public void setColuna(int coluna) {
    this.coluna = coluna;
}
public void setLinha(int linha) {
    this.linha = linha;
}
public String getTexto() {
    return texto;
}
public void setTexto(String texto) {
    this.texto = texto;
}
public long getId() {
    return id;
}
public void setId(long id) {
    this.id = id;
}

}

Piece of code of VerticeDAO Class:

public boolean salvaAtualiza(Vertice VerticeArg) throws ViolacaoChaveUnicaException{

boolean ret = false;

try{
     if(VerticeArg.equals(null)){
        throw new Exception("O objeto <Vertice> foi informado vazio.");
     }
     else{
        sess.beginTransaction();
        sess.saveOrUpdate(VerticeArg);
        ret = true;
     }
    }
    catch(ConstraintViolationException e){
        throw new ViolacaoChaveUnicaException(
           "Houve uma violação de chave na tentativa " + 
              "de gravar os dados no BD");
    }
    catch(Exception e){
        e.printStackTrace();
    }
    return ret;
}

XML of Vertex Entity (Vertice.hbm.xml):

<hibernate-mapping>
<class name="xx.xxx.xxx.Vertice" table="pcommjava_vertice">
    <id name="id" column="vertice_id" type="long">
        <generator class="native" />
    </id>
    <property name="amostra">
        <column name="vertice_amostra" not-null="true" length="1920"/>
    </property>
    <property name="chave">
        <column name="vertice_chave" not-null="true" length="50" unique="true" unique-key="vertice_chave"/>
    </property>
    </class>

Tag XML mapping (Tag.hbm.xml):

<hibernate-mapping>
<class name="xx.xxx.xxx.Tag" table="pcommjava_tag">
    <id name="id" column="tag_id" type="long">
        <generator class="native" />
    </id>
    <property name="linha">
        <column name="tag_linha" not-null="true" />
    </property>
    <property name="coluna">
        <column name="tag_coluna" not-null="true" />
    </property>
    <property name="texto">
        <column name="tag_texto" not-null="true" />
    </property>

    <many-to-one name="vertice" cascade="all" not-null="true" column="tag_vertice" class="xx.xxx.xxx.Vertice" />

</class>

Finally, the hibernate.cfg.xml:

 <hibernate-configuration>
 <session-factory>
  <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
  <property name="hibernate.connection.password">SOMEPASSWORD</property>
  <property name="hibernate.connection.url">jdbc:mysql://00.00.000.000:3306/DB2</property>
  <property name="hibernate.connection.username">developer</property>
  <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
  <property name="hibernate.current_session_context_class">thread</property>
  <property name="hibernate.show_sql">true</property>
  <property name="hibernate.format_sql">true</property>
  <!-- Automatic schema creation (begin) === -->
  <property name="hibernate.hbm2ddl.auto">create</property>
  <!-- Simple memory-only cache -->
  <property name="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property>

  <mapping class="xx.xx.xxx.Vertice"
   package="xx.xx.xxx.Vertice" resource="xx/xxx/xxx/Vertice.hbm.xml"/>
  <mapping class="xx.xx.xxx.Tag"
   package="xx.xx.xxx.Tag" resource="xx/xx/xxx/Tag.hbm.xml"/>

 </session-factory>

</hibernate-configuration>
  • 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-12T09:29:52+00:00Added an answer on June 12, 2026 at 9:29 am

    The problem is you haven’t defined set<Tag> in vertex.hbm.xml. According to my understanding, when you put Set in Vertice.java, it becomes either one-to-many or many-to-many relationship. In addition to this, if you put Vertice reference in Tag.java it becomes bi-directional relationship.
    For more info see this:

    http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/collections.html

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
This could be a duplicate question, but I have no idea what search terms
I've tracked down a weird MySQL problem to the two different ways I was
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I am trying to loop through a bunch of documents I have to put
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.