This week's book giveaway is in the HTML Pages with CSS and JavaScript forum.
We're giving away four copies of Testing JavaScript Applications and have Lucas da Costa on-line!
See this thread for details.
Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Repeated column in mapping for entity

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am trying to do an application in JPA with hibernate. But i am getting Repeated column in mapping for entity exception in my code. Please help me to correct if i am wrong in my code.

RegisterBean.java

public class RegisterBean
{
private String userName,password;

private long userID;
private Date dob;
@Embedded
@AttributeOverrides({
@AttributeOverride(name="street",column=@Column(name="home_street")),
@AttributeOverride(name="state",column=@Column(name="home_state")),
@AttributeOverride(name="houseNo",column=@Column(name="home_houseNo"))
})
private AddressClass homeAddressClass;
@Embedded
@AttributeOverrides({
@AttributeOverride(name="street",column=@Column(name="office_street")),
@AttributeOverride(name="state",column=@Column(name="office_state")),
@AttributeOverride(name="houseNo",column=@Column(name="office_houseNo"))
})
private AddressClass officeAddressClass;



@Id
@Column(name="user_id")
@GeneratedValue(strategy=GenerationType.AUTO)

public long getUserID()
{
return userID;
}

public void setUserID(long userID)
{
this.userID = userID;
}
@Temporal(TemporalType.TIMESTAMP)
public Date getDob() {
return dob;
}

public void setDob(Date dob) {
this.dob = dob;
}
@Column(name="user_name")

public String getUserName()
{
return userName;
}

public void setUserName(String userName)
{
this.userName = userName;
}

public String getPassword()
{
return password;
}

public void setPassword(String password)
{
this.password = password;
}

public AddressClass getHomeAddressClass() {
return homeAddressClass;
}

public void setHomeAddressClass(AddressClass homeAddressClass) {
this.homeAddressClass = homeAddressClass;
}

public AddressClass getOfficeAddressClass() {
return officeAddressClass;
}

public void setOfficeAddressClass(AddressClass officeAddressClass) {
this.officeAddressClass = officeAddressClass;
}

}

AddressClass.java

@Embeddable
public class AddressClass
{
@Column(name="office_street")
private String street;
@Column(name="office_state")
private String state;
@Column(name="office_houseNo")
private Long houseNo;

public String getStreet()
{
return street;
}
public void setStreet(String street)
{
this.street = street;
}

public String getState()
{
return state;
}
public void setState(String state)
{
this.state = state;
}

public Long getHouseNo()
{
return houseNo;
}
public void setHouseNo(Long houseNo)
{
this.houseNo = houseNo;
}

hibernate.cfg.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">;
<hibernate-configuration>


<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/shop</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>

<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1000</property>

<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>

<!-- Enable Hibernate's automatic session context management -->
<!-- <property name="current_session_context_class">thread</property> -->

<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>

<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>

<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">create</property>
<mapping class="com.all.RegisterBean" />

</session-factory>
</hibernate-configuration>

mainClass.java

public class HibernateCall
{
public static void main(String[] args)
{
RegisterBean registerBean=new RegisterBean();
AddressClass homeAddressClass=new AddressClass();
AddressClass officeAddressClass=new AddressClass();

registerBean.setUserName("t");
registerBean.setPassword("ti");
registerBean.setDob(new Date());
homeAddressClass.setStreet("tho");
homeAddressClass.setState("ke");
homeAddressClass.setHouseNo(13L);
registerBean.setHomeAddressClass(homeAddressClass);
officeAddressClass.setStreet("kot");
officeAddressClass.setState("k");
officeAddressClass.setHouseNo(14L);
registerBean.setOfficeAddressClass(officeAddressClass);
SessionFactory sessionFactory=new Configuration().configure().buildSessionFactory();
Session session=sessionFactory.openSession();
session.beginTransaction();
session.save(registerBean);
session.getTransaction().commit();
session.close();


}

error is

Exception in thread "main" org.hibernate.MappingException: Repeated column in mapping for entity: com.kjc.all.RegisterBean column: houseNo (should be mapped with insert="false" update="false")
at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:681)
at org.hibernate.mapping.PersistentClass.checkPropertyColumnDuplication(PersistentClass.java:703)
at org.hibernate.mapping.PersistentClass.checkPropertyColumnDuplication(PersistentClass.java:699)
at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:725)
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:478)
at org.hibernate.mapping.RootClass.validate(RootClass.java:270)
at org.hibernate.cfg.Configuration.validate(Configuration.java:1294)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1736)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1782)
at com.all.MainClass.main(MainClass.java:28)

i checked with insertable=false and updatable=false. even it is not worked for me.

any help will be appreciatable. Thanks in advance
 
She's out of the country right now, toppling an unauthorized dictatorship. Please leave a message with this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic