JavaWeb_ (Hibernate framework) Hibernate entity created

 

 

Hibernate entity created

  Create a solid five basic rules

    - provide no argument constructor

    - privatization member variables to provide get, set method, providing property

    - Try to use Package Type

    - the primary key (there must be)

    - Do not add Final (using a proxy mechanism hibernate in)

 

 

  No-argument constructor

First, the concept 
java Method is constructed: 
the same as the class name, a method of non-return type, parameters can be empty or can be parameterized. 
For example, a class Dao, Private Dao () {} This is the constructor with no arguments.
Private Dao (String name) {} This is the constructor arguments. 
Action: to initialize the java class and an initialization class is instantiated, to call. 
Second, the role of new objects when a constructor to use, e.g. Hello Hello
= new Hello (); this time is called no-argument constructor method Hello; Hello Hello = new Hello ( "Hi"); this is a call Hello there argument constructor, if not written in JAVA constructor, it will add a default constructor with no arguments, but if you already have a constructor parameter, then the no-argument constructor will not be added by default If you already have on a constructor parameter Hello class, the next time you use the Hello = Hello. new new Hello (); time to create objects will be wrong, which is why the book to emphasize wrote constructed with parameters the method is preferably applied to a constructor with no arguments.
Third, the difference has the main purpose constructor parameter is initialized class attributes without constructor parameters, new objects can be controlled. Suppose your lunch constructor is not public but modified project, then people will not only direct a new subject, which has played a controlling role. Why should automatically generated constructor with no arguments it
? You do not have a new construction method will not generate an object so give you a no-argument constructor general construction method is to control your new object there is the initialization properties

 

 

  And the difference between variable properties

  Class is a template to create an object, so it can construct a plurality of substantially identical objects. The class is defined, for example, String name; int, class standing position like age and so is the assignment can be repeated, so can be seen as a variable. As for the objects, it is the property of the object.

  

 

  Package Type   Liao Xuefeng: Package Type Portal

  Basic types can not be assigned null, packaging type can be assigned to null

  We already know, Java data types in two ways:

  • Basic bytetypes: short, int, long, boolean, float, double, ,char

  • Reference types: all classand interfacetypes

  Reference types can be assigned nullto indicate empty, but the basic types can not be assignednull,如果想要把int基本类型变成一个引用类型,我们可以定义一个Integer类,它只包含一个实例字段int,这样,Integer类就可以视为int的包装类(Wrapper Class)

 

 

  Do not add final

  • final class can not be inherited, no sub-class, the default class final method is final. 

  • final methods can not override methods by subclasses, but can be inherited. 

  • final member variable represents a constant, can only be assigned once, after the value assigned does not change. 

  • method can not be used to modify the final construction.

   Proxy mode hibernate framework is implemented by way of inheritance, here are final modified User class can not be inherited, then you can not generate the proxy object User

 

Guess you like

Origin www.cnblogs.com/1138720556Gary/p/11849249.html