domingo, 23 de diciembre de 2018

Gitlab SVN command line instructions

 Command line instructions

Git global setup
git config --global user.name "Jose Alberto Martinez"
git config --global user.email "jalbertomr@yahoo.com"
Create a new repository
git clone https://gitlab.com/jalbertomr/creaprueba.git
cd creaprueba
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master
Existing folder
cd existing_folder
git init
git remote add origin https://gitlab.com/jalbertomr/creaprueba.git
git add .
git commit -m "Initial commit"
git push -u origin master
Existing Git repository
cd existing_repo
git remote rename origin old-origin
git remote add origin https://gitlab.com/jalbertomr/creaprueba.git
git push -u origin --all
git push -u origin --tags

jueves, 6 de diciembre de 2018

TIBCO Business Works 6.5 Install ems-driver





Installing ems-driver

from windows power shell, execute
C:\Program Files\tibco\bw6\bw\6.5\bin> .\bwinstall.exe ems-driver

we'll get something like this
Buildfile: C:\Program Files\tibco\bw6\bw\6.5\scripts\bwinstall.xml

ems-driver:

-init-bw:

-ems-home-location:
    [input] Please enter full path to the EMS Home components plugin folder including the components folder (typically  EMS_HOME/components//shared/1.0.0/plugins) :
C:\Program Files\tibco\bw6\components\shared\1.0.0\plugins
     [echo]
     [echo] zip.dir: C:\Program Files\tibco\bw6\components\shared\1.0.0\plugins
     [echo] zip: C:\Program Files\tibco\bw6\components\shared\1.0.0\plugins
     [echo] tibco.home: C:/Program Files/tibco/bw6
     [echo] bw.home: C:/Program Files/tibco/bw6/bw/6.5
     [echo] tibco.java.home: C:/Program Files/tibco/bw6/tibcojre64/1.8.0

delete-jmsclient:
   [delete] Deleting C:\Program Files\tibco\bw6\bw\6.5\system\shared\com.tibco.jms.jmsclient.admin_8.1.0.010\META-INF\MANIFEST.MF
   [delete] Deleting C:\Program Files\tibco\bw6\bw\6.5\system\shared\com.tibco.jms.jmsclient.admin_8.1.0.010\plugin.properties
   [delete] Deleting C:\Program Files\tibco\bw6\bw\6.5\system\shared\com.tibco.jms.jmsclient.rv_8.1.0.010\META-INF\MANIFEST.MF
   [delete] Deleting C:\Program Files\tibco\bw6\bw\6.5\system\shared\com.tibco.jms.jmsclient.rv_8.1.0.010\plugin.properties
   [delete] Deleting C:\Program Files\tibco\bw6\bw\6.5\system\shared\com.tibco.jms.jmsclient.ufo_8.1.0.010\META-INF\MANIFEST.MF
   [delete] Deleting C:\Program Files\tibco\bw6\bw\6.5\system\shared\com.tibco.jms.jmsclient.ufo_8.1.0.010\plugin.properties
   [delete] Deleting C:\Program Files\tibco\bw6\bw\6.5\system\shared\com.tibco.jms.jmsclient_8.1.0.010\META-INF\MANIFEST.MF
   [delete] Deleting C:\Program Files\tibco\bw6\bw\6.5\system\shared\com.tibco.jms.jmsclient_8.1.0.010\plugin.properties
   [delete] Deleting C:\Program Files\tibco\bw6\bw\6.5\system\shared\com.tibco.jms.jmsclient_8.1.0.010\META-INF
   [delete] Deleting C:\Program Files\tibco\bw6\bw\6.5\system\shared\com.tibco.jms.jmsclient_8.1.0.010
   [delete] Deleting C:\Program Files\tibco\bw6\bw\6.5\system\shared\com.tibco.jms.jmsclient.ufo_8.1.0.010\META-INF
   [delete] Deleting C:\Program Files\tibco\bw6\bw\6.5\system\shared\com.tibco.jms.jmsclient.ufo_8.1.0.010
   [delete] Deleting C:\Program Files\tibco\bw6\bw\6.5\system\shared\com.tibco.jms.jmsclient.rv_8.1.0.010\META-INF
   [delete] Deleting C:\Program Files\tibco\bw6\bw\6.5\system\shared\com.tibco.jms.jmsclient.rv_8.1.0.010
   [delete] Deleting C:\Program Files\tibco\bw6\bw\6.5\system\shared\com.tibco.jms.jmsclient.admin_8.1.0.010\META-INF
   [delete] Deleting C:\Program Files\tibco\bw6\bw\6.5\system\shared\com.tibco.jms.jmsclient.admin_8.1.0.010

copy-new-jmsclient:
     [copy] Copying 12 files to C:\Program Files\tibco\bw6\bw\6.5\system\shared
     [copy] Copying C:\Program Files\tibco\bw6\components\shared\1.0.0\plugins\com.tibco.jms.jmsclient.admin_8.4.0.014\META-INF\MANIFEST.MF to C:\Program Files\tibco\bw6\bw\6.5\system\shared\com.tibco.jms.jmsclient.admin_8.4.0.014\META-INF\MANIFEST.MF
     [copy] Copying C:\Program Files\tibco\bw6\components\shared\1.0.0\plugins\com.tibco.jms.jmsclient.admin_8.4.0.014\plugin.properties to C:\Program Files\tibco\bw6\bw\6.5\system\shared\com.tibco.jms.jmsclient.admin_8.4.0.014\plugin.properties
     [copy] Copying C:\Program Files\tibco\bw6\components\shared\1.0.0\plugins\com.tibco.jms.jmsclient.admin_8.4.0.014\tibjmsadmin.jar to C:\Program Files\tibco\bw6\bw\6.5\system\shared\com.tibco.jms.jmsclient.admin_8.4.0.014\tibjmsadmin.jar
     [copy] Copying C:\Program Files\tibco\bw6\components\shared\1.0.0\plugins\com.tibco.jms.jmsclient.rv_8.4.0.014\META-INF\MANIFEST.MF to C:\Program Files\tibco\bw6\bw\6.5\system\shared\com.tibco.jms.jmsclient.rv_8.4.0.014\META-INF\MANIFEST.MF
     [copy] Copying C:\Program Files\tibco\bw6\components\shared\1.0.0\plugins\com.tibco.jms.jmsclient.rv_8.4.0.014\plugin.properties to C:\Program Files\tibco\bw6\bw\6.5\system\shared\com.tibco.jms.jmsclient.rv_8.4.0.014\plugin.properties
     [copy] Copying C:\Program Files\tibco\bw6\components\shared\1.0.0\plugins\com.tibco.jms.jmsclient.rv_8.4.0.014\tibrvjms.jar to C:\Program Files\tibco\bw6\bw\6.5\system\shared\com.tibco.jms.jmsclient.rv_8.4.0.014\tibrvjms.jar
     [copy] Copying C:\Program Files\tibco\bw6\components\shared\1.0.0\plugins\com.tibco.jms.jmsclient.ufo_8.4.0.014\META-INF\MANIFEST.MF to C:\Program Files\tibco\bw6\bw\6.5\system\shared\com.tibco.jms.jmsclient.ufo_8.4.0.014\META-INF\MANIFEST.MF
     [copy] Copying C:\Program Files\tibco\bw6\components\shared\1.0.0\plugins\com.tibco.jms.jmsclient.ufo_8.4.0.014\plugin.properties to C:\Program Files\tibco\bw6\bw\6.5\system\shared\com.tibco.jms.jmsclient.ufo_8.4.0.014\plugin.properties
     [copy] Copying C:\Program Files\tibco\bw6\components\shared\1.0.0\plugins\com.tibco.jms.jmsclient.ufo_8.4.0.014\tibjmsufo.jar to C:\Program Files\tibco\bw6\bw\6.5\system\shared\com.tibco.jms.jmsclient.ufo_8.4.0.014\tibjmsufo.jar
     [copy] Copying C:\Program Files\tibco\bw6\components\shared\1.0.0\plugins\com.tibco.jms.jmsclient_8.4.0.014\META-INF\MANIFEST.MF to C:\Program Files\tibco\bw6\bw\6.5\system\shared\com.tibco.jms.jmsclient_8.4.0.014\META-INF\MANIFEST.MF
     [copy] Copying C:\Program Files\tibco\bw6\components\shared\1.0.0\plugins\com.tibco.jms.jmsclient_8.4.0.014\plugin.properties to C:\Program Files\tibco\bw6\bw\6.5\system\shared\com.tibco.jms.jmsclient_8.4.0.014\plugin.properties
     [copy] Copying C:\Program Files\tibco\bw6\components\shared\1.0.0\plugins\com.tibco.jms.jmsclient_8.4.0.014\tibjms.jar to C:\Program Files\tibco\bw6\bw\6.5\system\shared\com.tibco.jms.jmsclient_8.4.0.014\tibjms.jar

setup-bwthor-launch:

-setup-bwthor-launch:
[setupbwthorlaunch] ==>TIBCO Home: C:/Program Files/tibco/bw6
[setupbwthorlaunch] ==>BW Home: C:/Program Files/tibco/bw6/bw/6.5
[setupbwthorlaunch] ==>BW Thor provisioning properties: C:/Program Files/tibco/bw6/eclipse-platform/bundlepool/1.0/org.eclipse.equinox.p2.touchpoint.eclipse/plugins/com.tibco.bw.thor.launch_1.3.700.001/provisioning.properties
==>INFO: Scanning bundles under: C:\Program Files\tibco\bw6\bw\6.5\system\hotfix\lib\common
==>INFO: Scanning bundles under: C:\Program Files\tibco\bw6\bw\6.5\system\lib\common
==>INFO: Scanning bundles under: C:\Program Files\tibco\bw6\bw\6.5\system\hotfix\shared
==>INFO: Scanning bundles under: C:\Program Files\tibco\bw6\bw\6.5\system\shared
==>INFO: Scanning bundles under: C:\Program Files\tibco\bw6\bw\6.5\system\hotfix\palettes
==>INFO: Scanning bundles under: C:\Program Files\tibco\bw6\bw\6.5\system\palettes
     [copy] Copying 1 file to C:\Program Files\tibco\bw6\eclipse-platform\bundlepool\1.0\org.eclipse.equinox.p2.touchpoint.eclipse\plugins\com.tibco.bw.thor.launch_1.3.700.001
     [copy] Copying 1 file to C:\Program Files\tibco\bw6\eclipse-platform\bundlepool\1.0\org.eclipse.equinox.p2.touchpoint.eclipse\plugins\com.tibco.bw.thor.launch_1.3.700.001
     [copy] Copying 1 file to C:\Program Files\tibco\bw6\eclipse-platform\bundlepool\1.0\org.eclipse.equinox.p2.touchpoint.eclipse\plugins\com.tibco.bw.thor.launch_1.3.700.001
     [copy] Copying 1 file to C:\Program Files\tibco\bw6\eclipse-platform\bundlepool\1.0\org.eclipse.equinox.p2.touchpoint.eclipse\plugins\com.tibco.bw.thor.launch_1.3.700.001
     [copy] Copying 1 file to C:\Program Files\tibco\bw6\eclipse-platform\bundlepool\1.0\org.eclipse.equinox.p2.touchpoint.eclipse\plugins\com.tibco.bw.thor.launch_1.3.700.001

copy-new-jmsclient-design:

-copy-new-jmsclient-design:
     [echo] emsclient.design.dir.path=C:\Program Files\tibco\bw6\eclipse-platform\bundlepool\1.0\org.eclipse.equinox.p2.touchpoint.eclipse\plugins\com.tibco.jms.jmsclient.eclipse_6.4.0.001
     [echo] jmsclient.src.dir.path=C:\Program Files\tibco\bw6\components\shared\1.0.0\plugins\com.tibco.jms.jmsclient_8.4.0.014

-copyEMSClientDesign:
     [copy] Copying 1 file to C:\Program Files\tibco\bw6\eclipse-platform\bundlepool\1.0\org.eclipse.equinox.p2.touchpoint.eclipse\plugins\com.tibco.jms.jmsclient.eclipse_6.4.0.001
     [copy] Copying C:\Program Files\tibco\bw6\components\shared\1.0.0\plugins\com.tibco.jms.jmsclient_8.4.0.014\tibjms.jar to C:\Program Files\tibco\bw6\eclipse-platform\bundlepool\1.0\org.eclipse.equinox.p2.touchpoint.eclipse\plugins\com.tibco.jms.jmsclient.eclipse_6.4.0.001\tibjms.jar

-copyJavaxJMSDesign:
     [copy] Copying 1 file to C:\Program Files\tibco\bw6\eclipse-platform\bundlepool\1.0\org.eclipse.equinox.p2.touchpoint.eclipse\plugins\com.tibco.tpcl.javax.jms.eclipse_1.10.0.001
     [copy] Copying C:\Program Files\tibco\bw6\components\shared\1.0.0\plugins\com.tibco.tpcl.javax.jms_2.0.0.002\jms-2.0.jar to C:\Program Files\tibco\bw6\eclipse-platform\bundlepool\1.0\org.eclipse.equinox.p2.touchpoint.eclipse\plugins\com.tibco.tpcl.javax.jms.eclipse_1.10.0.001\jms.jar
     [echo] emsclient.design.dir.path=C:\Program Files\tibco\bw6\eclipse-platform\bundlepool\1.0\org.eclipse.equinox.p2.touchpoint.eclipse\plugins\com.tibco.jms.jmsclient.eclipse_6.4.0.001
     [echo] jmsclient.src.dir.path=C:\Program Files\tibco\bw6\components\shared\1.0.0\plugins\com.tibco.jms.jmsclient_8.4.0.014

install-ems-driver:

BUILD SUCCESSFUL
Total time: 1 minute 12 seconds
PS C:\Program Files\tibco\bw6\bw\6.5\bin>

It will be installed as a Service on windows



from a command windows:

tcp://localhost:7222> connect tcp://localhost:7222
tcp://localhost:7222> admin
tcp://localhost:7222> show queues
                                                              All Msgs            Persistent Msgs
  Queue Name                        SNFGXIBCT  Pre  Rcvrs     Msgs    Size        Msgs    Size
  >                                 ---------    5*     0        0     0.0 Kb        0     0.0 Kb
  $sys.admin                        +--------    5*     0        0     0.0 Kb        0     0.0 Kb
  $sys.lookup                       ---------    5*     0        0     0.0 Kb        0     0.0 Kb
  $sys.redelivery.delay             +--------    5*     0        0     0.0 Kb        0     0.0 Kb
  $sys.undelivered                  +--------    5*     0        0     0.0 Kb        0     0.0 Kb
* $TMP$.EMS-SERVER.2AF45C0720E63.1  ---------    5      1        0     0.0 Kb        0     0.0 Kb
  queue.sample                      ---------    5*     0        0     0.0 Kb        0     0.0 Kb

  sample                            ---------    5*     0        0     0.0 Kb        0     0.0 Kb


jueves, 31 de mayo de 2018

Hibernate Road 3


@ManyToMany UserDetails a Vehicle y @ManyToMany Vehicle a UserDetails


Establezcamos una relación de muchos a muchos de UserDetails a Vehicle y viceversa, en otras palabras usuario puede tener varios vehículos, y también un vehículo puede tener varios usuarios.

UserDetails.java
@Entity
@Table (name="USER_DETAILS")
public class UserDetails {
       @Id @GeneratedValue(generator="vehicle-gen",strategy=GenerationType.AUTO)
       @GenericGenerator(name="vehicle-gen",strategy="sequence",
                                         parameters={@Parameter(name="sequence_name",value="seq_vehicle")}
                                  )
       private int userId;
       private String userName;
       @ManyToMany
       private Collection<Vehicle> vehicle = new ArrayList<Vehicle>();
setters y getters…
en Vehicle.java
@Entity
public class Vehicle {
       @Id @GeneratedValue(strategy=GenerationType.AUTO)
       private int vehicleId;
       private String vehicleName;
       @ManyToMany
       private Collection<UserDetails> userList = new ArrayList<UserDetails>();

En HibernateTest.java cargaremos datos a user y a vehicle.
public static void main(String[] args) {
             UserDetails userDetails = new UserDetails();
                          
             Vehicle vehicle1 = new Vehicle();
             vehicle1.setVehicleName("carrito");
             Vehicle vehicle2 = new Vehicle();
             vehicle2.setVehicleName("Audi");
                          
             userDetails.setUserName("Primer Usuario");
             userDetails.getVehicle().add(vehicle1);
             userDetails.getVehicle().add(vehicle2);
            
             vehicle1.getUserList().add(userDetails);
             vehicle2.getUserList().add(userDetails);
            
             SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
             Session session = sessionFactory.openSession();
             session.beginTransaction();
             session.save(userDetails);
             session.save(vehicle1);
             session.save(vehicle2);
             session.getTransaction().commit();
             session.close();
            
             //sessionFactory.close();
       }
 Al ejecutar el programa. Hibernate reporta en la consola, la creación de dos tablas de relación.
Hibernate: drop table if exists seq_vehicle
Hibernate: drop table if exists USER_DETAILS
Hibernate: drop table if exists USER_DETAILS_Vehicle
Hibernate: drop table if exists Vehicle
Hibernate: drop table if exists Vehicle_USER_DETAILS
Hibernate: create table hibernate_sequence (next_val bigint) engine=MyISAM
Hibernate: insert into hibernate_sequence values ( 1 )
Hibernate: create table seq_vehicle (next_val bigint) engine=MyISAM
Hibernate: insert into seq_vehicle values ( 1 )
Hibernate: create table USER_DETAILS (userId integer not null, userName varchar(255), primary key (userId)) engine=MyISAM
Hibernate: create table USER_DETAILS_Vehicle (UserDetails_userId integer not null, vehicle_vehicleId integer not null) engine=MyISAM
Hibernate: create table Vehicle (vehicleId integer not null, vehicleName varchar(255), primary key (vehicleId)) engine=MyISAM
Hibernate: create table Vehicle_USER_DETAILS (Vehicle_vehicleId integer not null, userList_userId integer not null) engine=MyISAM
Hibernate: alter table USER_DETAILS_Vehicle add constraint FKd6kp2c4oltmpsg6g9d8u15ymw foreign key (vehicle_vehicleId) references Vehicle (vehicleId)
Hibernate: alter table USER_DETAILS_Vehicle add constraint FKbdrxqw3j8dovf9npdkrfkpc3u foreign key (UserDetails_userId) references USER_DETAILS (userId)
Hibernate: alter table Vehicle_USER_DETAILS add constraint FK8t4fr6s5yx5sg3qquujrjn2w2 foreign key (userList_userId) references USER_DETAILS (userId)
Hibernate: alter table Vehicle_USER_DETAILS add constraint FK8mnn7v8pd5lo5asfwtvuwbfp3 foreign key (Vehicle_vehicleId) references Vehicle (vehicleId)
Hibernate: select next_val as id_val from seq_vehicle for update
Hibernate: update seq_vehicle set next_val= ? where next_val=?
Hibernate: select next_val as id_val from hibernate_sequence for update
Hibernate: update hibernate_sequence set next_val= ? where next_val=?
Hibernate: select next_val as id_val from hibernate_sequence for update
Hibernate: update hibernate_sequence set next_val= ? where next_val=?
Hibernate: insert into USER_DETAILS (userName, userId) values (?, ?)
Hibernate: insert into Vehicle (vehicleName, vehicleId) values (?, ?)
Hibernate: insert into Vehicle (vehicleName, vehicleId) values (?, ?)
Hibernate: insert into USER_DETAILS_Vehicle (UserDetails_userId, vehicle_vehicleId) values (?, ?)
Hibernate: insert into USER_DETAILS_Vehicle (UserDetails_userId, vehicle_vehicleId) values (?, ?)
Hibernate: insert into Vehicle_USER_DETAILS (Vehicle_vehicleId, userList_userId) values (?, ?)
Hibernate: insert into Vehicle_USER_DETAILS (Vehicle_vehicleId, userList_userId) values (?, ?)

Tabla UserDetails
userId userName
1 Primer Usuario

Tabla Vehicle
vehicleId vehicleName
1 carrito
2 Audi

Tabla Vehicle_USER_DETAILS
Vehicle_vehicleId userList_userId
1 1
2 1

Tabla USER_DETAILS_Vehicle
UserDetails_userId vehicle_vehicleId
1 1
1 2

Se puede observar que es redundante una de las dos tablas de relación que creo hibernate, con una sola sería suficiente, pare ello hay que indicar en la entidad que no queremos que genere la tabla de relación redundante Vehicle con @ManyToMany(mappedBy="vehicle").


@ManyToMany(mappedBy=”…”)


En Vehicle.java, indicamos con mappedBy=”vehicle” que use la propiedad “vehicle” de UserDetails.
@Entity
public class Vehicle {
       @Id @GeneratedValue(strategy=GenerationType.AUTO)
       private int vehicleId;
       private String vehicleName;
       @ManyToMany(mappedBy="vehicle")
       private Collection<UserDetails> userList = new ArrayList<UserDetails>();
            

Al ejecutar el programa de carga de prueba HibernateTest.java, observamos que ahora solo que crea una sola table de relación USER_DETAILS_Vehicle
Hibernate: drop table if exists hibernate_sequence
Hibernate: drop table if exists seq_vehicle
Hibernate: drop table if exists USER_DETAILS
Hibernate: drop table if exists USER_DETAILS_Vehicle
Hibernate: drop table if exists Vehicle
Hibernate: create table hibernate_sequence (next_val bigint) engine=MyISAM
Hibernate: insert into hibernate_sequence values ( 1 )
Hibernate: create table seq_vehicle (next_val bigint) engine=MyISAM
Hibernate: insert into seq_vehicle values ( 1 )
Hibernate: create table USER_DETAILS (userId integer not null, userName varchar(255), primary key (userId)) engine=MyISAM
Hibernate: create table USER_DETAILS_Vehicle (userList_userId integer not null, vehicle_vehicleId integer not null) engine=MyISAM
Hibernate: create table Vehicle (vehicleId integer not null, vehicleName varchar(255), primary key (vehicleId)) engine=MyISAM
Hibernate: alter table USER_DETAILS_Vehicle add constraint FKd6kp2c4oltmpsg6g9d8u15ymw foreign key (vehicle_vehicleId) references Vehicle (vehicleId)
Hibernate: alter table USER_DETAILS_Vehicle add constraint FK8a2f131hek5akrmni3vff2ivy foreign key (userList_userId) references USER_DETAILS (userId)
Hibernate: select next_val as id_val from seq_vehicle for update
Hibernate: update seq_vehicle set next_val= ? where next_val=?
Hibernate: select next_val as id_val from hibernate_sequence for update
Hibernate: update hibernate_sequence set next_val= ? where next_val=?
Hibernate: select next_val as id_val from hibernate_sequence for update
Hibernate: update hibernate_sequence set next_val= ? where next_val=?
Hibernate: insert into USER_DETAILS (userName, userId) values (?, ?)
Hibernate: insert into Vehicle (vehicleName, vehicleId) values (?, ?)
Hibernate: insert into Vehicle (vehicleName, vehicleId) values (?, ?)
Hibernate: insert into USER_DETAILS_Vehicle (userList_userId, vehicle_vehicleId) values (?, ?)
Hibernate: insert into USER_DETAILS_Vehicle (userList_userId, vehicle_vehicleId) values (?, ?)


@ManyToOne @NotFound(NotFoundAction.IGNORE)

Utilizado para cuando se quiere evitar una exception cuando no se encuentra la entidad.

CascadeTypes 

En acciones como guardar, actualizar sobre una entidad con entidades hijas como propiedades sobre las cuales se desea que dicha acción se aplique también a estas entidades hijas. en este ejemplo guardamos userDetails pero no vehicle, es entonces cuando se genera un error
object references an unsaved transient instance...

@OneToMany 

@Entity
@Table (name="USER_DETAILS")
public class UserDetails {
       @Id @GeneratedValue(generator="vehicle-gen",strategy=GenerationType.AUTO)
       @GenericGenerator(name="vehicle-gen",strategy="sequence",
                                         parameters={@Parameter(name="sequence_name",value="seq_vehicle")}
                                  )
       private int userId;
       private String userName;
       @OneToMany
       @JoinTable(name="USER_VEHICLE",joinColumns=@JoinColumn(name="USER_ID"),
                    inverseJoinColumns=@JoinColumn(name="VEHICLE_ID"))
       private Collection<Vehicle> vehicle = new ArrayList<Vehicle>();

@Entity
public class Vehicle {
       @Id @GeneratedValue(strategy=GenerationType.AUTO)
       private int vehicleId;
       private String vehicleName;

public static void main(String[] args) {
             UserDetails userDetails = new UserDetails();
                          
             Vehicle vehicle1 = new Vehicle();
             vehicle1.setVehicleName("carrito");
             Vehicle vehicle2 = new Vehicle();
             vehicle2.setVehicleName("Audi");
                          
             userDetails.setUserName("Primer Usuario");
             userDetails.getVehicle().add(vehicle1);
             userDetails.getVehicle().add(vehicle2);
            
            
             SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
             Session session = sessionFactory.openSession();
             session.beginTransaction();
             session.save(userDetails);
             //session.save(vehicle1);
             //session.save(vehicle2);
             session.getTransaction().commit();
             session.close();
            
             //sessionFactory.close();
       }

may 31, 2018 2:30:30 PM org.hibernate.internal.ExceptionMapperStandardImpl mapManagedFlushFailure
ERROR: HHH000346: Error during managed flush [org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance beforeQuery flushing: org.bext.dto.Vehicle]
Exception in thread "main" java.lang.IllegalStateException: org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance beforeQuery flushing: org.bext.dto.Vehicle

Agregando @OneToMany(cascade=CascadeType.PERSIST)

 Al calificar con cascade=CascadeType.PERSIST, no es necesario indicar en el código que guarde las entidades vehicle, pero si hay que indicar que se hace un persist() en lugar de un save().
@Entity
@Table (name="USER_DETAILS")
public class UserDetails {
       @Id @GeneratedValue(generator="vehicle-gen",strategy=GenerationType.AUTO)
       @GenericGenerator(name="vehicle-gen",strategy="sequence",
                                         parameters={@Parameter(name="sequence_name",value="seq_vehicle")}
                                  )
       private int userId;
       private String userName;
       @OneToMany(cascade=CascadeType.PERSIST)
       @JoinTable(name="USER_VEHICLE",joinColumns=@JoinColumn(name="USER_ID"),
                    inverseJoinColumns=@JoinColumn(name="VEHICLE_ID"))
       private Collection<Vehicle> vehicle = new ArrayList<Vehicle>();

En HibernateTest.java, cambiamos save a persist.
             SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
             Session session = sessionFactory.openSession();
             session.beginTransaction();
             session.persist(userDetails);
             //session.save(vehicle1);
             //session.save(vehicle2);
             session.getTransaction().commit();
             session.close();


Implementando Herencia

Herencia es una característica común en lenguajes OOP, pero para modelos entidad relación no es materia común. Hibernate da algunas opciones para implementar herencia.
@Entity
public class DosRuedas extends Vehicle {
       private String Manubrio;
…setters y getters…

@Entity
public class CuatroRuedas extends Vehicle {
       private String volante;
…setters y getters…

HibernateTest.java
public static void main(String[] args) {
       Vehicle vehicle = new Vehicle();
       vehicle.setVehicleName("transporte");
       DosRuedas bicicleta = new DosRuedas();
       bicicleta.setVehicleName("birula");
       bicicleta.setManubrio("Manubrio de bicicleta");
       CuatroRuedas automovil = new CuatroRuedas();
       automovil.setVehicleName("Audi");
       automovil.setVolante("volante de automovil");
                          
       SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
       Session session = sessionFactory.openSession();
       session.beginTransaction();
       session.save(vehicle);
       session.save(bicicleta);
       session.save(automovil);
       session.getTransaction().commit();
       session.close();
            
       //sessionFactory.close();
}

Hibernate crea una única table con columnas extras referentes a las propiedades de las clases hijas.

Tabla Vehicle
DTYPE vehicleId vehicleName Manubrio volante
Vehicle 1 transporte NULL NULL
DosRuedas 2 birula Manubrio de bicicleta NULL
CuatroRuedas 3 Audi NULL volante de automovil


@Inheritance(strategy=InheritanceType.SINGLE_TABLE)


Configurando valores y nombres en SINGLE_TABLE
Vehicle.java
@Entity
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(
             name="Tipo_Vehiculo",
             discriminatorType=DiscriminatorType.STRING)
public class Vehicle {
       @Id @GeneratedValue(strategy=GenerationType.AUTO)
       private int vehicleId;
       private String vehicleName;
DosRuedas.java
@Entity
@DiscriminatorValue("Bicicleta")
public class DosRuedas extends Vehicle {
       private String Manubrio;
CuatroRuedas.java
@Entity
@DiscriminatorValue("Carro")
public class CuatroRuedas extends Vehicle {
       private String volante;
Con estas configuraciones, obtenemos la table Vehicle con nombre de columna de discriminación con nombre Tipo_Vehiculo y valores como “Bicicleta” y “Carro”


Tabla Vehiculo customizada
Tipo_Vehiculo vehicleId vehicleName Manubrio volante
Vehicle 1 transporte NULL NULL
Bicicleta 2 birula Manubrio de bicicleta NULL
Carro 3 Audi NULL volante de automovil


@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)

La estratégia que crea una tabla por clase, es configurada con la anotación mostrada en el titulo de este párrafo. Con esto no es necesaria la anotación @DiscriminationColumn en la entidad padre y @DiscriminationValue en las entidades hijas.

Vehicle.java
@Entity
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
public class Vehicle {
       @Id @GeneratedValue(strategy=GenerationType.AUTO)
       private int vehicleId;
       private String vehicleName;

DosRuedas.java
@Entity
public class DosRuedas extends Vehicle {
       private String Manubrio;

CuatroRuedas.java
@Entity
public class CuatroRuedas extends Vehicle {
       private String volante;
Tabla Vehicle
vehicleId vehicleName
1 transporte

Tabla DosRuedas
vehicleId vehicleName Manubrio
2 birula Manubrio de bicicleta

Tabla CuatroRuedas
vehicleId vehicleName volante
3 Audi volante de automovil


@Inheritance(strategy=InheritanceType.JOINED)


Con la estratégia JOINED se crean tablas separadas por clase o entidad, y se relacionan con una columna clave, de tal forma que recuperar la información se hace por medio de un query join.
Vehicle.java
@Entity
@Inheritance
(strategy = InheritanceType.JOINED)
public class Vehiculo {
   
@Id
    @GeneratedValue
   
private int Id;
   
private String Name;

setters y getters
DosRuedas.java
@Entity

public class DosRuedas extends Vehiculo {

    private String Manubrio;


setters y getters

CuatroRuedas.java
@Entity

public class CuatroRuedas extends Vehiculo{

    private String volante;
 
setters y getters


Programa de Prueba
 
public class HibernateTest {

    public static void main(String[] args){

        EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("org.hibernate.tutorial.jpa");



        Vehiculo vehiculo = new Vehiculo();

        vehiculo.setName("Transporte");



        DosRuedas dosRuedas = new DosRuedas();

        dosRuedas.setName("bicicleta");

        dosRuedas.setManubrio("Manubrio de Bicicleta");



        CuatroRuedas cuatroRuedas = new CuatroRuedas();

        cuatroRuedas.setName("Audi");

        cuatroRuedas.setVolante("Volante de Audi");



        EntityManager entityManager = entityManagerFactory.createEntityManager();



        entityManager.getTransaction().begin();

        entityManager.persist(vehiculo);

        entityManager.persist(dosRuedas);

        entityManager.persist(cuatroRuedas);

        entityManager.getTransaction().commit();



        entityManagerFactory.close();



    }

}

Hibernate muestra en la consola

Hibernate: create table CuatroRuedas (volante varchar(255), Id integer not null, primary key (Id)) engine=MyISAM
Hibernate: create table DosRuedas (Manubrio varchar(255), Id integer not null, primary key (Id)) engine=MyISAM
Hibernate: create table Vehiculo (Id integer not null, Name varchar(255), primary key (Id)) engine=MyISAM
Hibernate: alter table CuatroRuedas add constraint FKhaimfgg1r4h57bbo2js59hqq2 foreign key (Id) references Vehiculo (Id)
Hibernate: alter table DosRuedas add constraint FKmdtgstld5lhffvuc9lx69xmhk foreign key (Id) references Vehiculo (Id)
Tue Jun 05 19:10:20 CDT 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Hibernate: select next_val as id_val from hibernate_sequence for update
Hibernate: update hibernate_sequence set next_val= ? where next_val=?
Hibernate: insert into Vehiculo (Name, Id) values (?, ?)
Hibernate: insert into Vehiculo (Name, Id) values (?, ?)
Hibernate: insert into DosRuedas (Manubrio, Id) values (?, ?)
Hibernate: insert into Vehiculo (Name, Id) values (?, ?)
Hibernate: insert into CuatroRuedas (volante, Id) values (?, ?)
jun 05, 2018 7:10:20 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl stop
INFO: HHH10001008: Cleaning up connection pool [jdbc:mysql://localhost:3306/wsp?zeroDateTimeBehavior=convertToNull]

tabla Vehiculo
Id Name
1 Transporte
2 bicicleta
3 Audi

Tabla DosRuedas
Manubrio Id
Manubrio de Bicicleta 2

Tabla CuatroRuedas
Manubrio Id
Manubrio de Bicicleta 2

La integración de los datos se hace con un join de las tablas

SELECT * FROM vehiculo 
JOIN cuatroruedas ON vehiculo.id = cuatroruedas.id;

Id Name volante Id
3 Audi Volante de Audi 3

SELECT * FROM vehiculo 
JOIN dosruedas ON vehiculo.id = dosruedas.id;

Id Name Manubrio Id
2 bicicleta Manubrio de Bicicleta 2


FinTexto