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?