Discussion:
[jboss-user] [JBoss Tools] - How to avoid should be mapped with insert="false" update="false"
Christian Filippi
2013-02-22 07:19:44 UTC
Permalink
Christian Filippi [https://community.jboss.org/people/christian1976] created the discussion

"How to avoid should be mapped with insert="false" update="false""

To view the discussion, visit: https://community.jboss.org/message/799016#799016

--------------------------------------------------------------
Hi
I'm facing a problem when i try to use the hql query editor in eclipse.
[Repeated column in mapping for entity (should be mapped with insert="false" update="false")]

I have my Mysql db filled with tables with relations and data
I need to generate all the reversed-eng classes and xml, so in the hibernate config i select Hibernate Version 3.6 (but seems that there are no differences if i choose other, like in the options, i can choose mysql innodb dialect or mysql... seems the same)

Then i open the "Hibernate Code generation configurations..."
I check in the Main:
Generate basic typed composite ids
Detect optimistic lock colums
Detect many-to-many tables
Detect one-to-one associations


In the Exporters:
Domain code (.java)
Hibernate XML Mappings
Hibernate XML configuration


The generation runs fine, but when i try to operate a simple hql query (from tablename) i got this error:
(generated by hbm2java)
Unhandled event loop exception
org.hibernate.MappingException: Repeated column in mapping for entity: my.test.hibernate.SicComDdtOut column: SCDO-comm (should be mapped with insert="false" update="false")


I understand where the problem is and how i can avoid it is explained(should be mapped with insert="false" update="false")
But, i have many tables with many relations, and i'm still developing the database, so that means that i'll make some changes for sure.
If i follow the suggestion i must edit each problem everytime that i re-generate the code.


So i'm asking for help, is that the right way to solve this problem?
Am i missing something?


Thankyou in advance.


I'm using:
Eclipse: Version: 4.2.1.v20120814-120134...
Hibernate Tools for Eclipse Version: 3.6.0.Final-v20121205-1936-B77

Please, forgive me if i posted in a wrong section. :)
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/799016#799016]

Start a new discussion in JBoss Tools at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2128]
Max Rydahl Andersen
2013-02-22 09:19:24 UTC
Permalink
Max Rydahl Andersen [https://community.jboss.org/people/maxandersen] created the discussion

"Re: How to avoid should be mapped with insert="false" update="false""

To view the discussion, visit: https://community.jboss.org/message/799032#799032

--------------------------------------------------------------
First we need to find out why there are repeated columns. That should not happen in the first place (unless you got some funky model and then it might be automatic generation of mappings is not possible).

So, why are there repeated columns ? whats your table / class layout?
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/799032#799032]

Start a new discussion in JBoss Tools at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2128]
Christian Filippi
2013-02-22 09:47:32 UTC
Permalink
Christian Filippi [https://community.jboss.org/people/christian1976] created the discussion

"Re: How to avoid should be mapped with insert="false" update="false""

To view the discussion, visit: https://community.jboss.org/message/799035#799035

--------------------------------------------------------------
hello,

my sql schema is:

CREATE TABLE `SIC-AMM-Aziende` (
  `SAA-id` int(5) NOT NULL,
  `SAA-cat_id` int(2) DEFAULT NULL,
  `SAA-ragione_sociale` varchar(100) DEFAULT NULL,
  `SAA-piva` varchar(11) DEFAULT NULL,
  `SAA-note` varchar(300) DEFAULT NULL,
  `SAA-indirizzo-std` int(5) DEFAULT NULL,
  `SAA-pagamento-std` int(2) DEFAULT '0',
  PRIMARY KEY (`SAA-id`),
  KEY `SAA-cat_id` (`SAA-cat_id`),
  KEY `SAA-indirizzo-std` (`SAA-indirizzo-std`),
  KEY `SAA-pagamento-std` (`SAA-pagamento-std`),
  CONSTRAINT `***@002dAMM@002dAziende_ibfk_1` FOREIGN KEY (`SAA-indirizzo-std`) REFERENCES `SIC-AMM-Indirizzi` (`SAI-id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `***@002dAMM@002dAziende_ibfk_2` FOREIGN KEY (`SAA-pagamento-std`) REFERENCES `SIC-AMM-Pagamenti` (`SAP-id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=latin1$$




CREATE TABLE `SIC-AMM-Scadenze` (
  `SAS-id` int(11) NOT NULL,
  `SAS-ordine` int(11) DEFAULT NULL,
  `SAS-fornitore` int(5) DEFAULT NULL,
  `SAS-data` date DEFAULT NULL,
  `SAS-banca` tinyint(4) DEFAULT NULL,
  `SAS-importo` double DEFAULT NULL,
  `SAS-scaduto` enum('N','Y') DEFAULT NULL,
  PRIMARY KEY (`SAS-id`),
  KEY `SAS-ordine` (`SAS-ordine`),
  KEY `SAS-fornitore` (`SAS-fornitore`),
  KEY `SAS-banca` (`SAS-banca`),
  CONSTRAINT `SAS-banca` FOREIGN KEY (`SAS-banca`) REFERENCES `SIC-AMM-Banche` (`SAB-id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `SAS-fornitore` FOREIGN KEY (`SAS-fornitore`) REFERENCES `SIC-AMM-Aziende` (`SAA-id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `SAS-ordine` FOREIGN KEY (`SAS-ordine`) REFERENCES `SIC-COM-Ordini` (`SCR-id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=latin1$$




Please note the foreign key


CONSTRAINT `SAS-fornitore` FOREIGN KEY (`SAS-fornitore`) REFERENCES `SIC-AMM-Aziende` (`SAA-id`) ON DELETE NO ACTION ON UPDATE NO ACTION in SIC-AMM-Scadenze Table.




Generated Java code:




package it.scm.hibernate;


// Generated Feb 22, 2013 9:46:34 AM by Hibernate Tools 3.4.0.CR1


import java.util.HashSet;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;


/**
* SicAmmAziende generated by hbm2java
*/
@Entity
@Table(name = "SIC-AMM-Aziende", catalog = "SICIMI_DB")
public class SicAmmAziende implements java.io.Serializable {


          private int saaId;
          private Integer saaCatId;
          private String saaRagioneSociale;
          private String saaPiva;
          private String saaNote;
          private Integer saaIndirizzoStd;
          private Integer saaPagamentoStd;
          private Set<SicAmmScadenze> sicAmmScadenzes = new HashSet<SicAmmScadenze>(0);


          public SicAmmAziende() {
          }


          public SicAmmAziende(int saaId) {
                    this.saaId = saaId;
          }


          public SicAmmAziende(int saaId, Integer saaCatId, String saaRagioneSociale,
                              String saaPiva, String saaNote, Integer saaIndirizzoStd,
                              Integer saaPagamentoStd, Set<SicAmmScadenze> sicAmmScadenzes) {
                    this.saaId = saaId;
                    this.saaCatId = saaCatId;
                    this.saaRagioneSociale = saaRagioneSociale;
                    this.saaPiva = saaPiva;
                    this.saaNote = saaNote;
                    this.saaIndirizzoStd = saaIndirizzoStd;
                    this.saaPagamentoStd = saaPagamentoStd;
                    this.sicAmmScadenzes = sicAmmScadenzes;
          }


          @Id
          @Column(name = "SAA-id", unique = true, nullable = false)
          public int getSaaId() {
                    return this.saaId;
          }


          public void setSaaId(int saaId) {
                    this.saaId = saaId;
          }


          @Column(name = "SAA-cat_id")
          public Integer getSaaCatId() {
                    return this.saaCatId;
          }


          public void setSaaCatId(Integer saaCatId) {
                    this.saaCatId = saaCatId;
          }


          @Column(name = "SAA-ragione_sociale", length = 100)
          public String getSaaRagioneSociale() {
                    return this.saaRagioneSociale;
          }


          public void setSaaRagioneSociale(String saaRagioneSociale) {
                    this.saaRagioneSociale = saaRagioneSociale;
          }


          @Column(name = "SAA-piva", length = 11)
          public String getSaaPiva() {
                    return this.saaPiva;
          }


          public void setSaaPiva(String saaPiva) {
                    this.saaPiva = saaPiva;
          }


          @Column(name = "SAA-note", length = 300)
          public String getSaaNote() {
                    return this.saaNote;
          }


          public void setSaaNote(String saaNote) {
                    this.saaNote = saaNote;
          }


          @Column(name = "SAA-indirizzo-std")
          public Integer getSaaIndirizzoStd() {
                    return this.saaIndirizzoStd;
          }


          public void setSaaIndirizzoStd(Integer saaIndirizzoStd) {
                    this.saaIndirizzoStd = saaIndirizzoStd;
          }


          @Column(name = "SAA-pagamento-std")
          public Integer getSaaPagamentoStd() {
                    return this.saaPagamentoStd;
          }


          public void setSaaPagamentoStd(Integer saaPagamentoStd) {
                    this.saaPagamentoStd = saaPagamentoStd;
          }


          @OneToMany(fetch = FetchType.LAZY, mappedBy = "sicAmmAziende")
          public Set<SicAmmScadenze> getSicAmmScadenzes() {
                    return this.sicAmmScadenzes;
          }


          public void setSicAmmScadenzes(Set<SicAmmScadenze> sicAmmScadenzes) {
                    this.sicAmmScadenzes = sicAmmScadenzes;
          }


}




package it.scm.hibernate;


// Generated Feb 22, 2013 9:46:34 AM by Hibernate Tools 3.4.0.CR1


import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;


/**
* SicAmmScadenze generated by hbm2java
*/
@Entity
@Table(name = "SIC-AMM-Scadenze", catalog = "SICIMI_DB")
public class SicAmmScadenze implements java.io.Serializable {


          private int sasId;
          private SicAmmAziende sicAmmAziende;
          private Integer sasOrdine;
          private Integer sasFornitore;
          private Date sasData;
          private Byte sasBanca;
          private Double sasImporto;
          private String sasScaduto;


          public SicAmmScadenze() {
          }


          public SicAmmScadenze(int sasId) {
                    this.sasId = sasId;
          }


          public SicAmmScadenze(int sasId, SicAmmAziende sicAmmAziende,
                              Integer sasOrdine, Integer sasFornitore, Date sasData,
                              Byte sasBanca, Double sasImporto, String sasScaduto) {
                    this.sasId = sasId;
                    this.sicAmmAziende = sicAmmAziende;
                    this.sasOrdine = sasOrdine;
                    this.sasFornitore = sasFornitore;
                    this.sasData = sasData;
                    this.sasBanca = sasBanca;
                    this.sasImporto = sasImporto;
                    this.sasScaduto = sasScaduto;
          }


          @Id
          @Column(name = "SAS-id", unique = true, nullable = false)
          public int getSasId() {
                    return this.sasId;
          }


          public void setSasId(int sasId) {
                    this.sasId = sasId;
          }


          @ManyToOne(fetch = FetchType.LAZY)
          @JoinColumn(name = "SAS-fornitore")
          public SicAmmAziende getSicAmmAziende() {
                    return this.sicAmmAziende;
          }


          public void setSicAmmAziende(SicAmmAziende sicAmmAziende) {
                    this.sicAmmAziende = sicAmmAziende;
          }


          @Column(name = "SAS-ordine")
          public Integer getSasOrdine() {
                    return this.sasOrdine;
          }


          public void setSasOrdine(Integer sasOrdine) {
                    this.sasOrdine = sasOrdine;
          }


          @Column(name = "SAS-fornitore")
          public Integer getSasFornitore() {
                    return this.sasFornitore;
          }


          public void setSasFornitore(Integer sasFornitore) {
                    this.sasFornitore = sasFornitore;
          }


          @Temporal(TemporalType.DATE)
          @Column(name = "SAS-data", length = 10)
          public Date getSasData() {
                    return this.sasData;
          }


          public void setSasData(Date sasData) {
                    this.sasData = sasData;
          }


          @Column(name = "SAS-banca")
          public Byte getSasBanca() {
                    return this.sasBanca;
          }


          public void setSasBanca(Byte sasBanca) {
                    this.sasBanca = sasBanca;
          }


          @Column(name = "SAS-importo", precision = 22, scale = 0)
          public Double getSasImporto() {
                    return this.sasImporto;
          }


          public void setSasImporto(Double sasImporto) {
                    this.sasImporto = sasImporto;
          }


          @Column(name = "SAS-scaduto", length = 2)
          public String getSasScaduto() {
                    return this.sasScaduto;
          }


          public void setSasScaduto(String sasScaduto) {
                    this.sasScaduto = sasScaduto;
          }


}


The problem is about the column SAS-fornitore that is present two times:






@Column(name = "SAS-fornitore")
          public Integer getSasFornitore() {
                    return this.sasFornitore;
          }


          public void setSasFornitore(Integer sasFornitore) {
                    this.sasFornitore = sasFornitore;
          }


@ManyToOne(fetch = FetchType.LAZY)
          @JoinColumn(name = "SAS-fornitore")
          public SicAmmAziende getSicAmmAziende() {
                    return this.sicAmmAziende;
          }


          public void setSicAmmAziende(SicAmmAziende sicAmmAziende) {
                    this.sicAmmAziende = sicAmmAziende;
          }


Thanks in advance
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/799035#799035]

Start a new discussion in JBoss Tools at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2128]
Max Rydahl Andersen
2013-02-22 11:09:15 UTC
Permalink
Max Rydahl Andersen [https://community.jboss.org/people/maxandersen] created the discussion

"Re: How to avoid should be mapped with insert="false" update="false""

To view the discussion, visit: https://community.jboss.org/message/799048#799048

--------------------------------------------------------------
I dont see any " SCDO-comm " in this mapping ?
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/799048#799048]

Start a new discussion in JBoss Tools at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2128]
Christian Filippi
2013-02-22 12:48:55 UTC
Permalink
Christian Filippi [https://community.jboss.org/people/christian1976] created the discussion

"Re: How to avoid should be mapped with insert="false" update="false""

To view the discussion, visit: https://community.jboss.org/message/799063#799063

--------------------------------------------------------------
Hi,
i have many tables, in the example i reported the same problem with other tables.
:)
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/799063#799063]

Start a new discussion in JBoss Tools at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2128]
Christian Filippi
2013-02-23 10:01:02 UTC
Permalink
Christian Filippi [https://community.jboss.org/people/christian1976] created the discussion

"Re: How to avoid should be mapped with insert="false" update="false""

To view the discussion, visit: https://community.jboss.org/message/799193#799193

--------------------------------------------------------------
A friend solved the problem.
Seems that the error is generated due to my mistake in naming database tables and fields.
I used to name tables and fields with "-", and it's bad.
Seems that renaming all without using "-" solve the issue
:)
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/799193#799193]

Start a new discussion in JBoss Tools at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2128]
Denis Golovin
2013-02-25 22:41:28 UTC
Permalink
Denis Golovin [https://community.jboss.org/people/dgolovin] created the discussion

"Re: How to avoid should be mapped with insert="false" update="false""

To view the discussion, visit: https://community.jboss.org/message/799479#799479

--------------------------------------------------------------
Actually '-' is permitted character in MySQL quoted identifiers ('-' code is U+002D)
* ASCII: U+0001 .. U+007F
* Extended: U+0080 .. U+FFFF
It means your schema was correct and the problem is somewhere else.
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/799479#799479]

Start a new discussion in JBoss Tools at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2128]
Loading...