Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Hibernate creating table in hibernate
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


pratik garg
creating table in hibernate
3 Answer(s)      4 years and 2 months ago
Posted in : Hibernate


how to create table by the help of hibernate


Advertisement
View Answers

November 9, 2010 at 3:07 PM


There are 2 alternatives to create table in hibernate:

1.) .hbm.xml

2.) Annotation.

Example 1: via .hbm.xml

==========================================

/* Class Course */

package com.mypkg.course;

import java.io.Serializable;

public class Course implements Serializable {

/**
 * 
 */
private static final long serialVersionUID = 1L;
private long courseID;
private String courseName;

public Course() {
    super();
}

public Course(String courseName) {
    super();
    this.courseName = courseName;
}

public long getCourseID() {
    return courseID;
}

public void setCourseID(long courseID) {
    this.courseID = courseID;
}

public String getCourseName() {
    return courseName;
}

public void setCourseName(String courseName) {
    this.courseName = courseName;
}

}

/* Course.hbm.xml */

This class contains course details.

Example 2: via Annotation

==========================================

package mypkg.course;

import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.Table;

@Entity @Table(name = "TBLCOURSES") public class Course {

private int courseID;
private String courseName;

@Id
@GeneratedValue
@Column(name = "COURSEID")
public int getCourseID() {
    return courseID;
}

public void setCourseID(int courseID) {
    this.courseID = courseID;
}

@Column(name = "COURSENAME")
public String getCourseName() {
    return courseName;
}

public void setCourseName(String courseName) {
    this.courseName = courseName;
}

public Course(String courseName) {
    super();
    this.courseName = courseName;
}

public Course() {
    super();
}

}

I think that this much is efficient for your problem. For any further issues feel free to ask.

+++++++++++++ knapster +++++++++++++



November 9, 2010 at 3:18 PM


thanks a ton,

But i want to create a new table in my oracle database by the help of hibernate, so if you would help me regarding this please tell me about that with example, it is very urgent to me and i didn't get any other source to ask this question..



November 9, 2010 at 4:21 PM


< property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver

< property name="hibernate.connection.url">jdbc racle:thin:@127.0.0.1:1521 XYZ

< property name="hibernate.connection.username">sys

< property name="hibernate.connection.password">dba

< property name="hibernate.connection.pool_size">10

< property name="show_sql">true

< property name="dialect">org.hibernate.dialect.OracleDialect

create configuration file for oracle database. I think it will solve ur prob.



Related Tutorials/Questions & Answers:
creating table in hibernate
creating table in hibernate  how to create table by the help of hibernate   There are 2 alternatives to create table in hibernate: 1... javax.persistence.Table; @Entity @Table(name = "TBLCOURSES") public class Course
creating instance of table in jsp
creating instance of table in jsp  i face senario look kie as follows... file is obviously a jsp page and shows the output in table manner. 3) now i want to make the instance of the data present in that paarticular table.... how i do
Advertisements
java coding for creating table in the console
java coding for creating table in the console  write a java program to create table
Hibernate Temporary Table
Hibernate Temporary Table   How can i create temporary table in Hibernate
how to creating hbm files in hibernate using Myeclipse
how to creating hbm files in hibernate using Myeclipse  how to creating hbm files in hibernate using Myeclipse
How to update table in Hibernate
How to update table in Hibernate  Hi, I have a table in database that has two fields in it. Student Name and ID, can anyone explain me how to update these tables in Hibernate. Thanks.   Update table query in Hibernate
Hibernate Creating criteria instance
Hibernate Creating criteria instance In this section you will learn about the creating of criteria instance in Hibernate. An instance of Criteria is created... a table from where you will required to retrieve a stored data to as a search result
Joining Multiple table in Hibernate
Joining Multiple table in Hibernate  Hi everyone, I'm new to Hibernate (even in JAVA), and I'm having some doubt's about one thing. I created 2... (using System.out.println) the query results. I've been using (just for one table
delete row from a table in hibernate
delete row from a table in hibernate  is there method to delete row in a table using hibernate like save(-) to insert row
Creating Hibernate Sessions and Transactions through Spring - AOP .
Creating Hibernate Sessions and Transactions through Spring - AOP .  Hi, I am facing some technical issues in creating the Hibernate Sessions and Transactions using Spring-AOP. Can you provide a sample code where Hibernate
Creating Hibernate Sessions and Transactions through Spring - AOP .
Creating Hibernate Sessions and Transactions through Spring - AOP .  Hi, I am facing some technical issues in creating the Hibernate Sessions and Transactions using Spring-AOP. Can you provide a sample code where Hibernate
Creating Hibernate Sessions and Transactions through Spring - AOP .
Creating Hibernate Sessions and Transactions through Spring - AOP .  Hi, I am facing some technical issues in creating the Hibernate Sessions and Transactions using Spring-AOP. Can you provide a sample code where Hibernate
Creating Hibernate Sessions and Transactions through Spring - AOP .
Creating Hibernate Sessions and Transactions through Spring - AOP .  Hi, I am facing some technical issues in creating the Hibernate Sessions and Transactions using Spring-AOP. Can you provide a sample code where Hibernate
Creating Hibernate Sessions and Transactions through Spring - AOP .
Creating Hibernate Sessions and Transactions through Spring - AOP .  Hi, I am facing some technical issues in creating the Hibernate Sessions and Transactions using Spring-AOP. Can you provide a sample code where Hibernate
Retrieve Value from Table - Hibernate
Retrieve Value from Table   Hai friend, I need help, How can i retrieve values From database using hibernate in web Application. As I new to hibernate I couldn't find solution for this problem.. Can anyone help please.. 
creating and executing stored procedure using hibernate
creating and executing stored procedure using hibernate  I have to execute following query using hibernate DECLARE @i_STARTDATETIME DATETIME DECLARE @i_ENDDATETIME DATETIME DECLARE @o_ERRORCODE INT DECLARE @o_ERRORDESCRIPTION
can we update table in hibernate with out primary key in table?
can we update table in hibernate with out primary key in table?  can we update table in hibernate with out primary key in table
Session #1 - Hibernate introduction and creating CRUD application
Session #1 - Video tutorial of Hibernate introduction and creating CRUD application. Example code of insert, update, search and delete data using Hibernate...: Here is the SQL code for creating table for running this application: DROP TABLE
Creating a Hash Table
Creating a Hash Table : Java Util   ... table. What is the hash table and how to create that? Hash Table holds... for several values. Hash Table is created using an algorithm (hashing function
Creating Table in Echo3
Creating Table in Echo3     ... in the nextapp.echo.app package. There are four constructors provided for creating a table in Echo3.... In this example of creating Table in Echo3 we have created a simple application
Hibernate 4 create Session Factory: Example of creating Session Factory in Hibernate 4
for creating the application. Hibernate 4 is undoubtedly very popular and robust framework for creating enterprise application. Hibernate 4.3.0 is the JPA... the code for creating the SessionFactory instance in your application. Hibernate
Delete database Table through hibernate and Spring
Delete database Table through hibernate and Spring  Hi, I am using Spring,Hibernate and Tapestry to save and also fetch data simultaneously from... once without repetation,or Detete table after data is fetched. Here
Creating table using DBCP
= con.createStatement(); String QueryString = "CREATE TABLE user_master1(User_Id INTEGER...(QueryString); System.out.println("Table created!!"); con.close(); } catch
Hibernate Criteria load all objects from table
Hibernate Criteria load all objects from table - Learn how to load all... the data from a table then you can easily use the Hibernate Criteria load all... the Hibernate Criteria Query to fetch all data from a table. Read more
How to import data from sql server table into an excel file by creating the rows dynamically in the excel according to the dataabase??
How to import data from sql server table into an excel file by creating... data from sql server table into an excel file by creating the rows dynamically in the excel according to the dataabase?? There is a table in sql server having
delete row from a table using hibernate
delete row from a table using hibernate  //code in java file String hql="delete from CONTACT c where ID=6"; Query query=session.createQuery(hql); //error when executing above code CONTACT is not mapped
MySQL Create Table
MySQL Create Table       Here, you will read the brief description about the MySQL create table. The CREATE TABLE statement is used for creating a table in database. 
Creating a MySQL Database Table to store Java Types
Creating a MySQL Database Table to store Java Types... are providing you an example with code for creating a table to store java types. Brief... to store a java types in our database table. Now one question may arise in your
Hibernate Insert
This tutorial will help you to learn how to insert data into table by using hibernate
table
table  multiplicatyion table
hibernate
hibernate  when we using schemaExport in hibernate every time it drops the existing table and create new table ,if table contain dependent table then is it drop
 

 

 

DMCA.com