1. Ant(Another Neat Tool) installation location
eclipse/plugins/org.apache.ant_1.9.2.v201404171502
2. Using for loop in ant
Copy the ant-contrib.jar to Eclipse/plugins/org.apache.ant_1.9.2.v201404171502/lib
Add the same jar to Window-> Preferances-> Ant ->Runtime ->Ant Home Entries-> add external jars (Specify the location of ant-contrib.jar)
<project name="projectName" xmlns:ac="antlib:net.sf.antcontrib>
< target name="forLoopExample>
<a:for list="1,2,3,4" param = "val">
<sequential>
<echo message = "val = @{val}"/>
</sequential>
</ac:for>
</target>
</project>
Result:
Buildfile: build.xml
[echo] val = 1
[echo] val = 2
[echo] val = 3
[echo] val = 4
[echo] val = 9
BUILD SUCCESSFUL
Total time: 2 seconds
3. Right click in eclipse is not working
Restart Eclipse with a "-clean" option
Open Command Prompt
Go to Eclipse installation location
Type
./Eclipse -clean
Open a command prompt (click Start, Run... enter "cmd"), then go to the directory where you have Eclipse installed with "cd ", and then run "eclipse -clean".
4. Hibernate tools Plugin for Eclipse Installation
For Eclipse 3.6, the URL is ” http://download.jboss.org/jbosstools/updates/stable/helios/ ”
In Eclipse IDE, menu bar, select “Help” >> “Install New Software …” , put the Eclipse update site URL.
Type “hibernate” in the filter box, to list down the necessary components for Hibernate tools. Select all the “Hibernate Tools” components and click next to download.
After the download progress is completed, restart Eclipse to take effect.
If Hibernate tools is installed properly, you are able to see the “Hibernate Perspective” in “Windows” >> “Open Perspective” >> “Others“.
5. Hibernate Tools
1. Hibernate Perspective
Open your “Hibernate Perspective“. In Eclipse IDE, select “Windows” >> “Open Perspective” >> “Others…” , choose “Hibernate“.
2. New Hibernate Configuration
In Hibernate Perspective, right click and select “Add Configuration…”
3. Set Classpath of Hibernate
You need to add the database driver to your classpath
1) Download the driver for your database
2) Point to it by clicking 'Add external jars' and selecting it from the place you downloaded it to
4. Generating Hibernate configuration file
In “Edit Configuration” dialog box,
In “Project” box, click on the “Browse..” button to select your project.
In “Database Connection” box, click “New..” button to create your database settings.
We need to specify the driver and connection details there
In “Configuration File” box, click “Setup” button to create a new or use existing “Hibernate configuration file”, hibernate.cfg.xml.
Source: http://www.mkyong.com/hibernate/how-to-install-hibernate-tools-in-eclipse-ide/
5. Creating a Hibernate Mapping File
Hibernate mapping files are used to specify how your objects relate to database tables.
To create basic mappings for properties and associations, i. e. generate .hbm.xml files, Hibernate Tools provide a basic wizard which you can display by selecting File → New → Hibernate XML mapping file.
At first you will be asked to select a package or multiple individual classes to map. It is also possible to create an empty file: do not select any packages or classes and an empty .hbm file will be created in the specified location.
Using the depth control option you can define the dependency depth used when choosing classes.
The next wizard page lists the mappings to be generated.
The next wizard page display a preview of the generated .hbm files.
Clicking the Finish button creates the files.
Source: https://access.redhat.com/documentation/en-US/Red_Hat_JBoss_Developer_Studio/7.0/html/Hibernate_Tools_Reference_Guide/map_file_wizard.html
6.Hibernate Configuration files
The basic structure of a Java Application using Hibernate consist of the following files:
- hibernate.cfg.xml- It consist of the database connection details
- modelClass.hbm.xml- It describes the mapping between the POJO and the corresponding table in the database
- hibernate.reveng.xml- This is the reverse Engineering file for Hibernate
7. Hibernate types
A Hibernate type is a bridge between an SQL type and a Java primitive/Object type.
These are the types Hibernate supports by default:
Hibernate type (org.hibernate.type)
|
JDBC type
|
Java type
|
StringType
|
VARCHAR
|
String
|
MaterializedClob
|
CLOB
|
String
|
TextType
|
LONGVARCHAR
|
String
|
CharacterType
|
CHAR
|
char or Character
|
BooleanType
|
BIT
|
boolean or Boolean
|
Numeric
|
INTEGER (e.g. 0 = false and 1 =
true)
|
BooleanType boolean or Boolean
|
YesNoType
|
CHAR (e.g. ‘N’ or ‘n’ = false and
‘Y’ or ‘y’ = true)
|
boolean or Boolean
|
TrueFalseType
|
CHAR (e.g. ‘F’ or ‘f’ = false and
‘T’ or ‘t’ = true)
|
boolean or Boolean
|
ByteType
|
TINYINT
|
byte or Byte
|
ShortType
|
SMALLINT
|
short or Short
|
IntegerType
|
INTEGER
|
int or Integer
|
LongType
|
BIGINT
|
long or Long
|
FloatType
|
FLOAT
|
float or Float
|
DoubleType
|
DOUBLE
|
double or Double
|
BigIntegerType
|
NUMERIC
|
BigInteger
|
BigDecimalType
|
NUMERIC
|
BigDecimal
|
TimestampType
|
TIMESTAMP
|
java.sql.Timestamp or
java.util.Date
|
TimeType
|
TIME
|
java.sql.Time
|
DateType
|
DATE
|
java.sql.Date
|
CalendarType
|
TIMESTAMP
|
java.util.Calendar or
java.util.GregorianCalendar
|
CalendarType
|
DATE
|
java.util.Calendar or
java.util.GregorianCalendar
|
CurrencyType
|
VARCHAR
|
java.util.Currency
|
LocaleType
|
VARCHAR
|
java.util.Locale
|
TimeZoneType
|
VARCHAR
|
java.util.TimeZone
|
UrlType
|
VARCHAR
|
java.net.URL
|
ClassType
|
VARCHAR
|
java.lang.Class
|
BlobType
|
BLOB
|
java.sql.Blob
|
ClobType
|
CLOB
|
java.sql.Clob
|
BinaryType
|
VARBINARY
|
byte[] or Byte[]
|
BinaryType
|
BLOB
|
byte[] or Byte[]
|
BinaryType
|
LONGVARBINARY
|
byte[] or Byte[]
|
BinaryType
|
LONGVARBINARY
|
byte[] or Byte[]
|
CharArrayType
|
VARCHAR
|
char[] or Character[]
|
UUIDBinaryType
|
BINARY
|
java.util.UUID
|
UUIDBinaryType
|
CHAR or VARCHAR
|
java.util.UUID
|
UUIDBinaryType
|
PostgreSQL UUID
|
java.util.UUID
|
SerializableType
|
VARBINARY
|
Serializable
|
8.org.hibernate.engine.jndi.JndiException: Error parsing JNDI name
Solution : Remove the name attribute from <session-factory> in hibernate.cfg.xml
9. Creating Jar using Ant
<target name="CreateJar" description="Create Jar file">
<jar jarfile="jarName.jar" basedir="src/"/>
</target>
You don’t write because you want to say something, you write because you have something to say.