NHibernate simple Hibernate config file: hibernate.cfg.xml

SQL Server Version

xmlversion=”1.0″ encoding=”utf-8″?>
<!– This is the System.Data.dll provider for SQL Server –>

<hibernate-configuration xmlns=”urn:nhibernate-configuration-2.2″ >
<session-factory name=”NHibernate.WebSQL”>

<property name=”connection.provider”>NHibernate.Connection.DriverConnectionProvider</property>
<property name=”connection.driver_class”>NHibernate.Driver.SqlClientDriver</property>
<property name=”connection.connection_string”>Server=serverInfowillbehere;User Id=username;Password=password;</property>
<property name=”dialect”>NHibernate.Dialect.MsSql2005Dialect</property>
<property name=”adonet.batch_size”>10</property>
<property name=”show_sql”>false</property>

<property name=”use_outer_join”>true</property>
<property name=”command_timeout”>444</property>
<property name=”query.substitutions”>true 1, false 0, yes ‘Y’, no ‘N'</property>

<mapping assembly=’Weditor.Core’ />


ORACLE version

xmlversion=”1.0″ encoding=”utf-8″?>
<!– This is the System.Data.dll provider for SQL Server –>
<hibernate-configuration xmlns=”urn:nhibernate-configuration-2.2″ >

<session-factory name=”NHibernate.WebORACLE”>
<property name=”connection.provider”>

<property name=”connection.driver_class”>
<property name=”connection.connection_string”>
Data Source=serverInfowillbehere;User Id=username;Password=password;

<property name=”dialect”>NHibernate.Dialect.Oracle9Dialect</property>
<property name=”command_timeout”>444</property>

<property name=”query.substitutions”>true 1, false 0, yes ‘Y’, no ‘N'</property>
<mapping assembly=’targetprojects.core’ />


java.util.zip Zip a file example

package test;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

 * @author tunatore
public class CreatingZIPfile {

    public void createZipFile() {

        try {

            File inputFile = new File(“C:\\test.txt”);
            File zipFile = new File(“C:\\compressed.zip”);

            //Create input and output streams
            FileInputStream inStream = new FileInputStream(inputFile);
            ZipOutputStream outStream = new ZipOutputStream(new FileOutputStream(zipFile));

            // Add a zip entry to the output stream
            outStream.putNextEntry(new ZipEntry(inputFile.getName()));

            byte[] buffer = new byte[Byte.MAX_VALUE];
            int bytesRead;

            //read from the input stream
            //write to the output stream
            while ((bytesRead = inStream.read(buffer)) > 0)
                outStream.write(buffer, 0, bytesRead);

            //Close zip entry and file streams


        } catch (IOException ex) {

    public static void main(String[] args)
        new CreatingZIPfile().createZipFile();

How to use DailyRollingFileAppender in log4j.xml

<appender name=”abcWebServiceDAILY_ROLLING_FILE”
<param name=”File” value=”/mainlog/abcWebService_mainapp.log” />
<param name=”Append” value=”true” />
<param name=”DatePattern” value=”‘.’dd-MM-yyyy” />
<param name=”ConversionPattern”
value=”[%d{ISO8601}] %-5p %m%n” />

<logger name=”com.blabla.abcWebServiceLogger” additivity=”false”>
<level value=”ERROR” />
<appender-ref ref=”abcWebServiceDAILY_ROLLING_FILE” />

If you want to define a DailyRollingFile for your project’s logs, then the configuration above will be worked.
Log files will be named and stored in the following format

abcWebService_mainapp.log –> today you can see the log file in this format

Oracle’s COALESCE function usage

COALESCE(expression1, expression2, expression(n)…)

–returns the first not NULL value in coalesce function list
–following example will return the address1 if is not null, or the second expression’s value will return
–if the address2 is NULL  then the last expression’s value ‘doesn’t have an address’ will return from the function

SELECT first_name, last_name, COALESCE(address1,address2,’doesn’t  have an address’ )
FROM employees
WHERE employee_id < 105;

FIRST_NAME           LAST_NAME                 HASANADDRESS                             
——————– ————————- —————————————-
Steven                     King                            doesn’t  have an address               
Neena                      Kochhar                    King St. …
Lex                          De Haan                     Main St. …                                      
Alexander                 Hunold                       Allday St. ..

Oracle’s NULLIF function


–ORACLE’s NULLIF function returns a NULL value if two expressions are equal
–otherwise expression1 is returned
–expression1 and expresion2 must have the same data types


–returns NULL if two expressions are equal
–I mean if max-salary – min_salary is 3000 then NULLIF returns NULL
–otherwise (max_salary- min_salary) result will return from the function

SELECT NULLIF((max_salary- min_salary), 3000)
FROM  jobs
WHERE max_salary < 10000;

NULL–max_salary and min_salary difference is 3000 here
NULL –max_salary and min_salary difference is 3000 here
NULL –max_salary and min_salary difference is 3000 here
NULL –max_salary and min_salary difference is 3000 here
NULL –max_salary and min_salary difference is 3000 here

Oracle’s Decode and Case usages

Let me give you a simple example like the below I have coded;

CASE usage;

SELECT firstname,lastname,
  WHEN customer_Id >= 0 AND customer_Id <= 1000 THEN ‘Regular Customer’
  WHEN customer_Id >= 1001 AND customer_Id <= 2000 THEN ‘Premium Customer’
  WHEN customer_Id >= 2001 AND customer_Id <= 3000 THEN ‘Corporate Customer’
  ELSE ‘Basic Customer’
FROM customers;

DECODE usage;

The following example, DECODE function takes customer_Id value and compare it with the second value which is NULL at this point and if they are equal then the third value (‘No Id was found’) replaced instead of using NULL.  If it is not NULL then the fourth column is used

–>syntax DECODE(colum_to_be_tested, test_expression,if_the_expression_is_TRUE,if_the_expression_is_FALSE)

SELECT firstname, DECODE(customer_Id,NULL,’No Id was found’,customer_Id), surname
FROM customers;

ORACLE’s Object Tables

You know, I have defined a new Oracle Data Type called book_type in my Database. Please refer it to by the following URL.


DESC book_type

–here our type definition
user type definition

TYPE  book_type  AS OBJECT (

published_year NUMBER(4)
4 rows selected

–now I would like to create an object table contaning many book_types inside of it
–object tables can only store types inside it

CREATE TABLE object_table_books OF book_type;

–However we can reference an object table in our standard table definition with REF
— keyword and SCOPE keyword
CREATE TABLE borrows (
 borrower VARCHAR2(100),
 book REF book_type  SCOPE IS object_table_books — reference to an object table

INSERT INTO object_table_books
VALUES (book_type(1111111,2009));
–we can insert book_type in this object table
–with this syntax
1 rows inserted.
INSERT INTO object_table_books
VALUES (book_type(2222222,2009));
1 rows inserted.

SELECT * FROM object_table_books;
–get newly inserted data

———————- ———————-
1111111                2009
2222222                2009                   

2 rows selected

INSERT INTO borrows (borrow_id, borrower, book)
(SELECT REF(otb) FROM object_table_books otb WHERE isbn_no = 1111111)
); — we must use REF keyword to map a book_type between borrow and object_table_books
–think this as a foreign key realitionship
1 rows inserted.

SELECT borrow_id, borrower,DEREF(book).isbn_no FROM borrows;

BORROW_ID              BORROWER                    DEREF(BOOK).ISBN_NO
———————- ————————— ———————-
1                                     tunatore                           1111111                

1 rows selected

–while selecting the data from a standard table containing a REF column data
— I should use DEREF keyword to get the data of REF column after getting
— the object moreover I can access its properties with dot notation

–on the other hand object table objects values can be get with
–VALUE keyword (alternative syntax)

SELECT VALUE(otb) FROM object_table_books otb;


2 rows selected

SELECT VALUE(otb).isbn_no FROM object_table_books otb;


2 rows selected