Search code examples
jakarta-eemodel

Which are the differences between Java entities and Java beans?


In Jakarta context, I would like to know the differences between those concepts.

As far as I know, Java entities represent entities of databases. On the other side, beans are like an abstraction of entities.

But I still do not get what "an abstraction of entities" means, and which is the usefulness of using beans, insead of simply using entities.


Solution

  • Java Entities is a ORM concept JPA in jakarta domain. Java beans is more broader concept.

    A JavaBean is a Java class that should follow the following conventions:
    
        It should have a no-arg constructor.
        It should be Serializable.
        It should provide methods to set and get the values of the properties, known as getter and setter methods.
    

    https://www.javatpoint.com/java-bean

    Any java class that conforms these rules is Java Bean it can be a Java Entity too.

    Entities are java classes which represents persistable domain objects. They are either annotated with @Entity or specified with configuration file to persist java objects and retrieve it from a datastore. Therefor fixing object relational impedance mismatch to think and work with persistent datasource with ease of mind.