Wednesday 8 June 2016

How to add missing src/test/java folder to the maven project in Eclipse

1) Create a folder test/java  under src folder
2) Right click on the project and choose Maven --> Update Project --> choose for Force update of Snapshot/Releases  and click ok.  Now  test folder should appear as src/test/java in Eclipse  project explorer

Tuesday 7 June 2016

How to configure dependencies for Spock+Groovy in maven project


Please use the below one in maven pom.xml

<!-- Groovy + Spock -->
<dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-core</artifactId>
<version>${org.spockframework.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-spring</artifactId>
<version>${org.spockframework.version}</version>
<scope>test</scope>
</dependency>
<dependency>
   <groupId>org.codehaus.groovy</groupId>
   <artifactId>groovy-all</artifactId>
   <version>${org.codehaus.groovy.version}</version>
 </dependency>
<dependency> <!-- enables mocking of classes (in addition to interfaces) -->
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>
<version>3.1</version>
<scope>test</scope>
</dependency>
<dependency> <!-- enables mocking of classes without default constructor (together with CGLIB) -->
<groupId>org.objenesis</groupId>
<artifactId>objenesis</artifactId>
<version>2.1</version>
<scope>test</scope>
</dependency>

How to resolve error "Caused by: org.hibernate.MappingException: Unable to find column with logical name: "

If you come across an error as like below

Caused by: org.hibernate.MappingException: Unable to find column with logical name: DESTINATION_ID  in org.hibernate.mapping.Table
(TRAVEL_DETAIL) and its related supertables and secondary tables
at org.hibernate.cfg.Ejb3JoinColumn.checkReferencedColumnsType(Ejb3JoinColumn.java:582)
at org.hibernate.cfg.BinderHelper.createSyntheticPropertyReference(BinderHelper.java:25

Please  remove the referencedColumnName attribute  which is used in Travel class  because destination_id is the primary key field of TravelDetail , referencedColumnName = ""  is only necessary if it references a non-primary-key field.

@Entity
public class Travel{

@Column(name="DESTINATION_ID" , insertable=false, updatable=false)
private java.math.BigDecimal destinationId;

//bi-directional many-to-one association to TravelDetail
@ManyToOne
@JoinColumns({
@JoinColumn(name="DESTINATION_ID" , referencedColumnName = "DESTINATION_ID")
})
private TravelDetail travelDetail;

.
.
.

}

@Entity
Public class TravelDetail{
@Id
@Column(name="\"DESTINATION_ID\"")
private long destinationId;
.
.
.

}

How to create random uuid or sequence for id generator through java.util.UUID

Below is way to create random UUID ,  this uuid can be used in place of sequencer (oracle sequence creation which will be provided in hibernate/jpa entities)


import java.util.UUID;

UUID.randomUUID().toString()

How to create Sequence in Oracle


Please use the below query to create sequence in Oracle. Here
MAXVALUE  -  denotes the maximum value that can be accoomdated
CACHE  - number of the values that will be created whenever nextval call is done and then put in cache
START WITH   -  the value that will begin with
INCREMENT BY   -  the incremental value

CREATE SEQUENCE <schema_name>.<sequence_name>
  MINVALUE 1
  MAXVALUE 99999999999
  START WITH 1
  INCREMENT BY 1
  CACHE 20;

ex:
CREATE SEQUENCE  TR.TRAVEL_DETAIL_ID_SEQ
  MINVALUE 1
  MAXVALUE 999999999999999999999
  START WITH 1
  INCREMENT BY 1
  CACHE 20;