Map Array For One To Many Map : Map Array « Hibernate « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Class
8. Collections Data Structure
9. Data Type
10. Database SQL JDBC
11. Design Pattern
12. Development Class
13. EJB3
14. Email
15. Event
16. File Input Output
17. Game
18. Generics
19. GWT
20. Hibernate
21. I18N
22. J2EE
23. J2ME
24. JDK 6
25. JNDI LDAP
26. JPA
27. JSP
28. JSTL
29. Language Basics
30. Network Protocol
31. PDF RTF
32. Reflection
33. Regular Expressions
34. Scripting
35. Security
36. Servlets
37. Spring
38. Swing Components
39. Swing JFC
40. SWT JFace Eclipse
41. Threads
42. Tiny Application
43. Velocity
44. Web Services SOA
45. XML
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java » Hibernate » Map ArrayScreenshots 
Map Array For One To Many Map

/////////////////////////////////////////////////////////////////////////

import java.util.Date;
import java.util.List;


import org.hibernate.*;
import org.hibernate.criterion.*;

public class SimpleRetrieveTest {
  
  
  public static void main(String[] args) {
    HibernateUtil.setup("create table A ( id int);");
    HibernateUtil.setup("create table B ( id int, aid int);");
    // hibernate code start
    Session session = HibernateUtil.currentSession();
    Transaction tx = session.beginTransaction();


    A a = new A();
    B b1 = new B();
    B b2 = new B();
    a.setBsnew B[] {b1, b2} );

    session.save(a);

        tx.commit();
    HibernateUtil.closeSession();

    HibernateUtil.sessionFactory.close();

    // hibernate code end
    HibernateUtil.checkData("select * from A");
    HibernateUtil.checkData("select * from B");    
  }
}


/////////////////////////////////////////////////////////////////////////
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC 
  "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
  "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<!-- 

  This mapping demonstrates content-based discrimination for the
  table-per-hierarchy mapping strategy, using a formula
  discriminator.

-->

<hibernate-mapping >
  
  <class name="A" lazy="true">
    
    <id name="id">
      <generator class="increment"/>
    </id>

    <array name="bs" cascade="all" fetch="join"  >
      <key column="aid"/>
      <list-index column="id"/>
      <one-to-many class="B"/>
    </array>

  </class>

  <class name="B" lazy="true">
    <id name="id">
      <generator class="increment"/>
    </id>
  </class>


</hibernate-mapping>





/////////////////////////////////////////////////////////////////////////


/**
 @author Emmanuel Bernard
 */
public class {
  private Integer id;
  private B[] bs;

  public Integer getId() {
    return id;
  }

  public void setId(Integer id) {
    this.id = id;
  }

  public B[] getBs() {
    return bs;
  }

  public void setBs(B[] bs) {
    this.bs = bs;
  }
}



/////////////////////////////////////////////////////////////////////////


/**
 @author Emmanuel Bernard
 */
public class {
  private Integer id;

  public Integer getId() {
    return id;
  }

  public void setId(Integer id) {
    this.id = id;
  }
}



/////////////////////////////////////////////////////////////////////////


<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>

    <session-factory>

        <!-- Database connection settings -->
        <property name="connection.driver_class">org.hsqldb.jdbcDriver</property>
        <property name="connection.url">jdbc:hsqldb:data/tutorial</property>
        <property name="connection.username">sa</property>
        <property name="connection.password"></property>

        <!-- JDBC connection pool (use the built-in-->
        <property name="connection.pool_size">1</property>

        <!-- SQL dialect -->
        <property name="dialect">org.hibernate.dialect.HSQLDialect</property>

        <!-- Echo all executed SQL to stdout -->
        <property name="show_sql">true</property>

        <mapping resource="A.hbm.xml"/>
    </session-factory>

</hibernate-configuration>

/////////////////////////////////////////////////////////////////////////
           
       
HibernateMapArrayForOneToManyMap.zip( 4,578 k)
Related examples in the same category
1. Map Array Retrieve Demo
2. Collection Mapping: Array
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.