I'm just getting started trying to use Hibernate to create a PostgreSQL database but keep getting this exception:
org.hibernate.HibernateException: java.lang.IllegalArgumentException: max size attribute is mandatory
It happens when I run my main method on the line where I try to build a session factory but I can't find anything about this exception anywhere online. I'm wondering anyone has any ideas on what could be causing this.
Main Class:
package com.package.ingestor;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class HibernateTest {
public static void main(String[] args){
Student user = new Student();
user.setStudentId(1);
user.setStudentName("Bri Guy");
user.setStudentAge(32);
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
Session session = sessionFactory.openSession();
session.beginTransaction();
session.save(user);
session.getTransaction().commit();
}
}
Hibernate Object:
package com.bossanova.ingestor;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
#Entity
#Table(name = "student", uniqueConstraints={#UniqueConstraint(columnNames={"id"})})
public class Student {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
#Column(name = "id", length=11, nullable=false, unique=true)
private Integer studentId;
#Column(name = "name", length=20, nullable=true)
private String studentName;
#Column(name="age", length=5, nullable=true)
private Integer studentAge;
public Student() { }
public Student(Integer studId, String studName, Integer studAge) {
this.studentId = studId;
this.studentName = studName;
this.studentAge = studAge;
}
public Integer getStudentId() {
return studentId;
}
public void setStudentId(Integer studentId) {
this.studentId = studentId;
}
public String getStudentName() {
return studentName;
}
public void setStudentName(String studentName) {
this.studentName = studentName;
}
public Integer getStudentAge() {
return studentAge;
}
public void setStudentAge(Integer studentAge) {
this.studentAge = studentAge;
}
#Override
public String toString() {
return "Student= Id: " + this.studentId + ", Name: " + this.studentName + ", Age: " + this.studentAge;
}
}
Config file:
<!DOCTYPE hibernate-configuration SYSTEM
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">org.postgresql.Driver</property>
<property name="connection.url">jdbc:postgresql://localhost:5433/hibernatedb</property>
<property name="connection.username">postgres</property>
<property name="connection.password">password</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQL95Dialect</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.bossanova.ingestor.Student"/>
</session-factory>
</hibernate-configuration>
I solved this for me by switching my Maven dependency from hibernate-agroal to hibernate-core.
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.4.0.Final</version>
</dependency>
If you are using hibernate-agroal add <type>pom</type> to your dependency
Related
I have a basic test for an embedded database that I'm trying to get working for a java project. As it stands now I am able to save rows to the database with my entity repository object, and after the app finishes running, I can connect to the database with intellij and see those rows are still there. But then, if I comment out the save methods and run it again, when I check the database after it finishes, the database is empty.
Entity
package closet.utilities.entities;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
#Entity
#Table(name = "outfits")
public class Outfit {
#Id
#Column(name = "id")
String id;
#Column(name = "inv_name")
String invName;
#Column(name = "display_name")
String displayName;
#Column(name = "owner")
String owner;
public Outfit() {
}
public Outfit(String id, String invName, String displayName, String owner) {
this.id = id;
this.invName = invName;
this.displayName = displayName;
this.owner = owner;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getInvName() {
return invName;
}
public void setInvName(String invName) {
this.invName = invName;
}
public String getDisplayName() {
return displayName;
}
public void setDisplayName(String displayName) {
this.displayName = displayName;
}
public String getOwner() {
return owner;
}
public void setOwner(String owner) {
this.owner = owner;
}
#Override
public String toString() {
return "Outfit{" +
"id='" + id + '\'' +
", invName='" + invName + '\'' +
", displayName='" + displayName + '\'' +
", owner='" + owner + '\'' +
'}';
}
}
Repository
package closet.utilities.repositories;
import closet.utilities.entities.Outfit;
import javax.persistence.EntityManager;
import java.util.List;
import java.util.Optional;
public class OutfitRepository {
private EntityManager entityManager;
public OutfitRepository(EntityManager entityManager) {
this.entityManager = entityManager;
}
public Optional<Outfit> findById(String id) {
Outfit outfit = entityManager.find(Outfit.class, id);
return outfit != null ? Optional.of(outfit) : Optional.empty();
}
public List<Outfit> findAll() {
return entityManager.createQuery("from Outfit").getResultList();
}
public Optional<Outfit> save(Outfit outfit) {
try {
entityManager.getTransaction().begin();
entityManager.persist(outfit);
entityManager.getTransaction().commit();
return Optional.of(outfit);
} catch (Exception e) {
// TODO logging
e.printStackTrace();
}
return Optional.empty();
}
}
main method
package closet.utilities;
import closet.utilities.entities.Outfit;
import closet.utilities.repositories.OutfitRepository;
import org.hibernate.Session;
import org.hibernate.Transaction;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import java.util.List;
public class Runnable {
public static void main(String[] args) {
// Create our entity manager
EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("closet");
EntityManager entityManager = entityManagerFactory.createEntityManager();
Outfit outfit = new Outfit("Ramesh", "Fadatare", "rameshfadatare#javaguides.com", "");
Outfit outfit1 = new Outfit("John", "Cena", "john#javaguides.com", "");
OutfitRepository outfitRepository = new OutfitRepository(entityManager);
//outfitRepository.save(outfit);
//outfitRepository.save(outfit1);
List<Outfit> outfits = outfitRepository.findAll();
for (Outfit o : outfits) {
System.out.println(o.getInvName());
}
}
}
persistence.xml
<persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="closet" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<class>closet.utilities.entities.Outfit</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.h2.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:h2:./data/closet" />
<property name="javax.persistence.jdbc.user" value="sa" />
<property name="javax.persistence.jdbc.password" value="" />
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
<property name="show_sql" value="true"/>
<property name="hibernate.temp.use_jdbc_metadata_defaults" value="false"/>
</properties>
</persistence-unit>
</persistence>
hibernate.cfg.xml
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- JDBC Database connection settings -->
<property name="connection.driver_class">org.h2.Driver</property>
<property name="connection.url">jdbc:h2:./data/closet</property>
<property name="connection.username">sa</property>
<property name="connection.password"></property>
<!-- JDBC connection pool settings ... using built-in test pool -->
<property name="connection.pool_size">1</property>
<!-- Select our SQL dialect -->
<property name="dialect">org.hibernate.dialect.H2Dialect</property>
<!-- Echo the SQL to stdout -->
<property name="show_sql">true</property>
<!-- Set the current session context -->
<property name="current_session_context_class">thread</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">create-drop</property>
<!-- dbcp connection pool configuration -->
<property name="hibernate.dbcp.initialSize">5</property>
<property name="hibernate.dbcp.maxTotal">20</property>
<property name="hibernate.dbcp.maxIdle">10</property>
<property name="hibernate.dbcp.minIdle">5</property>
<property name="hibernate.dbcp.maxWaitMillis">-1</property>
<mapping class="closet.utilities.entities.Outfit" />
</session-factory>
</hibernate-configuration>
I'm just following this tutorial here as a guide to just figure out how to get it all working. I can't see what I'm doing wrong based on that.
You use:
<property name="hbm2ddl.auto">create-drop</property>
As it is stated in the documentation:
create-drop
Drop the schema and recreate it on SessionFactory startup. Additionally, drop the schema on SessionFactory shutdown.
So, this is expected behaviour.
I am trying to write my first hibernate annotation application and below are the things that i did
package org.hibernate.pojo;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
#Entity
#Table(name="employee")
public class Employee {
#Id
#GeneratedValue
Integer id;
#Column(name="Employee_Name")
String userName;
#Column(name="Address")
String age;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
/**
* Hi this is to test java commenting
* #return
*/
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getAge() {
return age;
}
public void setAge(String age) {
this.age = age;
}
}
Hibernate.config.xml
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.password">$Ailaja12</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/sessions</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.bytecode.use_reflection_optimizer">false</property>
<!-- <property name="show_sql">true</property> -->
<!-- <mapping resource="org/hibernate/pojo/Employee.xml"></mapping> -->
<mapping class="org.hibernate.pojo.Employee"/>
<mapping resource="org/hibernate/pojo/Item.xml"></mapping>
</session-factory>
</hibernate-configuration>
Client
package org.hibernate.client;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;
import org.hibernate.pojo.Employee;
public class Client {
/**
* #param args
*/
public static void main(String[] args) {
//Starting hibernate environment in your application
Configuration conf = new Configuration();
//2 Loading hibernate configuration file
conf.configure("hibernate.cfg.xml");
SessionFactory factory=new AnnotationConfiguration().configure("hibernate.cfg.xml").buildSessionFactory();
//SessionFactory factory = conf.buildSessionFactory();
Session session = factory.getCurrentSession();
Employee ee = new Employee();
ee.setUserName("Kranthi");
//ee.setId(123);
ee.setAge("Dallas");
Transaction tx = session.beginTransaction();
session.save(ee);
tx.commit();
session.close();
factory.close();
}
}
I am getting below exception
Exception in thread "main" org.hibernate.MappingException: An AnnotationConfiguration instance is required to use
I tried by googling but none of them has worked
and below are the list of jars that i have used
antlr_2.7.6.jar
asm-3.3.1.jar
cglib-2.2.2.jar
domj-1.3.jar
ehcache.jar
hibernate-3.2.jar
javax.persistence.jar
jta.jar
mysql-connector.jar
commonlogging.jar
Add below jar to your class path: hibernate-annotations.3.3.0.GA.jar or add below dependency to your pom file,if you are using maven project
<dependency>
<groupId>hibernate-annotations</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.3.0.GA</version>
</dependency>
I'm learning Hibernates and while practising I came across this strange problem. Sometimes, when I do my changes and run the program, all of a sudden my Eclipse console gets stuck showing the last line as Hibernate: drop table UserDetails. To get the program running I need to restart my Eclipse program.
Below is my code.
UserDetails.java
package org.hibernates.dto;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
#Entity
public class UserDetails {
#Id
#Column(name = "User_ID")
private int userId;
#Column(name = "User_Name")
private String userName;
#Temporal(TemporalType.TIME)
private Date date;
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getDesription() {
return desription;
}
public void setDesription(String desription) {
this.desription = desription;
}
#Lob
private String address;
private String desription;
public int getUserId() {
return userId;
}
public void setUserId(int userId) {
this.userId = userId;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
}
HibernatesTest.java
package org.hibernates.dto;
import java.util.Date;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
public class HibernatesTest {
public static void main(String[] args) {
UserDetails user = new UserDetails();
user.setUserId(1);
user.setUserName("User 1");
user.setDate(new Date());
user.setAddress("User Address");
user.setDesription("User Desription");
Configuration configuration = new Configuration().configure();
StandardServiceRegistryBuilder builder = (StandardServiceRegistryBuilder) new StandardServiceRegistryBuilder()
.applySettings(configuration.getProperties());
ServiceRegistry serviceRegistry = builder.build();
SessionFactory factory = configuration.buildSessionFactory(serviceRegistry);
Session session = factory.openSession();
Transaction tx = session.beginTransaction();
session.save(user);
tx.commit();
session.close();
}
}
hibernate.cfg.xml
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
<property name="connection.url">jdbc:sqlserver://U0138039-TPD-A\\SQLEXPRESS:1433;DatabaseName=HibernatesDataBase</property>
<property name="connection.username">sa</property>
<property name="connection.password">T!ger123</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.SQLServer2005Dialect</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>
<!-- Names the annotated entity class -->
<mapping class="org.hibernates.dto.UserDetails" />
</session-factory>
</hibernate-configuration>
How can I fix this?
You need to close the session factory
factory.close()
guys i am newbie in hibernate .. i am trying to use annotation in hibernate but it gives me an exception .. here is my code .. any suggestions .. thanks in advance
in hibernate.cfg.xml
<?xml version='1.0' encoding='utf-8'?>
<hibernate-configuration>
<session-factory>
<!-- Related to the connection START -->
<property name="connection.driver_class">com.mysql.jdbc.Driver </property>
<property name="connection.url">jdbc:mysql://localhost:3306/mydb </property>
<property name="connection.user">root </property>
<property name="connection.password">root</property>
<!-- Related to the connection END -->
<!-- Related to hibernate properties START -->
<property name="show_sql">true</property>
<property name="dialet">org.hibernate.dialet.MYSQLDialet</property>
<property name="hbm2ddl.auto">create</property>
<!-- Related to hibernate properties END-->
<!-- Related to mapping START-->
<mapping resource="user.hbm.xml" />
<!-- Related to the mapping END -->
</session-factory>
</hibernate-configuration>
DataProvider.java
import javax.persistence.*;
#Entity
#Table(name="dataprovider")
public class DataProvider {
#Id #GeneratedValue
#Column(name="id")
private int user_id;
#Column(name="name")
private String user_name;
#Column(name="description")
private String user_desc;
public int getUser_id() {
return user_id;
}
public void setUser_id(int user_id) {
this.user_id = user_id;
}
public String getUser_name() {
return user_name;
}
public void setUser_name(String user_name) {
this.user_name = user_name;
}
public String getUser_desc() {
return user_desc;
}
public void setUser_desc(String user_desc) {
this.user_desc = user_desc;
}
}
in InsertData.java
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;
public class InsertData {
private static SessionFactory factory;
public static void main(String[] args) {
factory = new AnnotationConfiguration().configure("hibernate.cfg.xml").addAnnotatedClass(DataProvider.class)
.buildSessionFactory();
new InsertData().insertInfo();
}
public void insertInfo() {
Session session = factory.openSession();
DataProvider provider = new DataProvider();
provider.setUser_id(121);
provider.setUser_name("name");
provider.setUser_desc("desc");
Transaction tr = session.beginTransaction();
session.save(provider);
System.out.println("Object Saved");
tr.commit();
session.close();
factory.close();
}
}
the exception
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at org.hibernate.cfg.annotations.Version.<clinit>(Version.java:12)
at org.hibernate.cfg.AnnotationConfiguration.<clinit>(AnnotationConfiguration.java:78)
at InsertData.main(InsertData.java:11)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
All dependencies required by Hibernate are not loaded, if you use maven all jars referenced are automatically loaded in the Application classpath.
As your error is clearly saying , you are missing a reference to the sl4j jar.
https://www.google.co.in/url?sa=t&rct=j&q=&esrc=s&source=web&cd=7&cad=rja&uact=8&ved=0ahUKEwiBxfuDrM_LAhWCVI4KHU2uBZYQFghAMAY&url=http%3A%2F%2Fmvnrepository.com%2Fartifact%2Forg.slf4j%2Fslf4j-api&usg=AFQjCNFZmEX-pLO1rqWxEyCRGohyjvgEFw
The exception is quite clear: the class org.slf4j.LoggerFactory is required by Hibernate, but was not found. You need to add the corresponding Library to your classpath, i.e. you need an slf4j.jar in addition to hibernate.jar.
.hibernate.MappingException: Repeated column in mapping for entity: com.sample.User2 column: CITY_NAME (should be mapped with insert="false" update="false")
is the Exception I am getting when I run my program that uses Hibernate and MSSQL Server. Here is my code, which is from an online tutorial. I am not sure where the issue lies and I have of course Googled a lot but everything I found had a more obvious error. I can't seem to find it here. Keep in mind, this is my second day using Hibernate/JPA.
com.sample.Address.java:
package com.sample;
import javax.persistence.Column;
import javax.persistence.Embeddable;
#Embeddable
public class Address {
#Column(name="CITY_STREET")
private String street;
#Column(name="CITY_NAME")
private String city;
#Column(name="STATE")
private String state;
#Column(name="CITY_ZIP")
private String zip;
public Address() { }
public Address(String street, String city, String state, String zip) {
this.street = street;
this.city = city;
this.state = state;
this.zip = zip;
}
//Setters and getters generate by Eclipse (omitted for length)
//Note: No annotations on methods
}
com.sample.User2:
package com.sample;
import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
#Entity
#Table(name="FancyTable")
public class User2 {
#Id
#GeneratedValue(strategy=GenerationType.IDENTITY)
#Column(name="USER_ID")
private int userId;
#Column(name="USER_NAME")
private String userName;
#Embedded
#AttributeOverrides({
#AttributeOverride(column = #Column(name="HOME_STREET_NAME"), name = "CITY_STREET"),
#AttributeOverride(column = #Column(name="HOME_CITY_NAME"), name = "CITY_NAME"),
#AttributeOverride(column = #Column(name="HOME_STATE"), name = "STATE"),
#AttributeOverride(column = #Column(name="HOME_CITY_ZIP"), name = "CITY_ZIP")})
private Address homeAddress;
#Embedded
private Address officeAddress;
public User2() { }
//Setters and getters generated by Eclipse (Omitted for length)
//Note: No annotations on methods
}
com.sample.HibernateTest3.java:
package com.sample;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
public class HibernateTest3 {
static void run() {
User2 user = new User2();
User2 user2 = new User2();
user.setUserName("Test");
user2.setUserName("Test 2");
Address add1 = new Address();
add1.setStreet("street 1");
add1.setCity("city 1");
add1.setState("state 1");
add1.setZip("zip 1");
Address add2 = new Address();
add2.setStreet("street 2");
add2.setCity("city 2");
add2.setState("state 2");
add2.setZip("zip 2");
user.setHomeAddress(add1);
user2.setHomeAddress(add2);
user.setOfficeAddress(new Address("a", "b", "c", "d"));
user.setOfficeAddress(new Address("X", "X", "X", "X"));
SessionFactory sf = null;
try {
sf = HibernateUtils.createSessionFactory();
Session session = sf.openSession();
session.beginTransaction();
session.save(user);
session.save(user2);
session.getTransaction().commit();
} catch (Exception e) {
System.out.println("ERROR");
e.printStackTrace();
} finally {
try {
HibernateUtils.close();
} catch (Exception ex) {
System.out.println("ERROR 2");
ex.printStackTrace();
}
}
}
public static void main(String[] args) {
run();
}
}
And finally, my hibernate.cfg.xml file...
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
<property name="connection.url">jdbc:sqlserver://localhost:1433;databaseName=sample1</property>
<property name="connection.username">sa</property>
<property name="connection.password">OMMITED</property>
<!-- MSSQL Dialect -->
<property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</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>
<!-- Names the annotated entity class -->
<mapping class="com.sample.User2"/>
</session-factory>
</hibernate-configuration>
Can someone please shed some light and tell me what precisely is causing this error?
From the docs of #AttributeOverride
(Required) The name of the property whose mapping is being overridden
if property-based access is being used, or the name of the field if
field-based access is used.
so you should use a field name instead of column names e.g.
#AttributeOverride(column = #Column(name="HOME_STREET_NAME"), name = "street")
otherwise the column name is not changed and you get your exception