0

I am working on a small example where I am giving a name for my entity and referring to it in Session.save() method, but I am not able t understand how this works because if I pass an invalid name to Session.save() even then my program is working fine.

Here is my entity class Cat.java:

@Entity(name="TestingCat")
@Table(name = "TEST_CAT")
public class Cat {
    @Id
    @GeneratedValue
    private int id;
    private String name;
}

and my code that uses Session.save():

Session session = getSession();
session.getTransaction().begin();    
Cat cat = new Cat();
cat.setName("My Cat");
session.save("Hello",cat);
session.getTransaction().commit();
session.refresh(cat);

In this program I am giving wrong name to my entity, so I was expecting an exception with this code, but even then my code is working fine. Can someone please tell me what is the purpose of this entity name?

learner
  • 6,062
  • 14
  • 79
  • 139
  • possible duplicate of [What is entityName parameter in save method?](http://stackoverflow.com/questions/13951990/what-is-entityname-parameter-in-save-method) – Aleksandr M Sep 17 '14 at 11:22

1 Answers1

0

It is the name of the entity, which's mapping you are using - you can have multiple mappings for an entity.

The wrong name probably defaults to something and it can be found out from Hibernate source code to what exactly. You can start digging from here.

See also:

Community
  • 1
  • 1
heikkim
  • 2,955
  • 2
  • 24
  • 34