Results 1 to 3 of 3
  1. #1
    ajhansiprasad is offline Member
    Join Date
    Nov 2008
    Posts
    1
    Rep Power
    0

    Exclamation new to hibernate

    i am using myEclipse with hibernate when running command->from table_name<- in Hql editor error occur i.e. org.hibernate.hql.ast.QuerySyntaxException: table_name is not mapped [from Table_name] but i configured hibernate reverse engineering.

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    I don't know much about hibernate, but seems to me you have an issue with your query. Re-check it again.

  3. #3
    racerxadam is offline Member
    Join Date
    Jul 2008
    Posts
    68
    Rep Power
    0

    Default

    In order to run the HQL query

    Java Code:
    from table_name
    you need to map the java object "table_name" to a table in the database you are working with using either a .hbm file or the

    Java Code:
    @Entity
    @Table(name=table_name)
    annotations

    For instance suppose I have an object Person.java that corresponds to a table in my database called Person. Person.java has 3 fields personGuid, firstName, and lastName. If I want to get all of the records from that table I would execute the query
    Java Code:
    from Person
    and my Person.hbm would have a mapping something like

    PHP Code:
    <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC
    	"-//Hibernate/Hibernate Mapping DTD//EN"
    	"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
    
    <hibernate-mapping package="com.myPackage">
    	<class
    		lazy="false"
    		name="Person"
    		table="Person"
    	>
    		
    		<id
    			column="PersonGuid"
    			name="personGuid"
    			type="string"
    		>
    			<generator class="com.myPackage.utl.MyGuidGeneratorUtl">
    				<param name="id">personGuid</param>
    			</generator>
    		</id>
    		<property
    			column="FirstName"
    			length="36"
    			name="firstName"
    			not-null="false"
    			type="string"
    		 />
    		<property
    			column="LastName"
    			length="36"
    			name="lastName"
    			not-null="false"
    			type="string"
    		 />
         </class>
    </hibernate-mapping>
    The Person.hbm would then be included in the hibernate.cfg.xml so that hibernate knows about the mapping when it starts up. Alternatively you can use annotations to specify the mapping of your objects like this:

    Person.java

    PHP Code:
    package com.myPackage;
    
    import java.io.Serializable;
    
    @Entity
    @Table(name=Person)
    public class Person implements Serializable{
    	@Id
    	private String personGuid;
    
    	private String firstName;
    	private String lastName;
    
    	public String getPersonGuid() {
    		return personGuid;
    	}
    	private void setPersonGuid(String personGuid) {
    		this.personGuid = personGuid;
    	}
    	public String getFirstName() {
    		return firstName;
    	}
    	public void setFirstName(String firstName) {
    		this.firstName = firstName;
    	}
    	public String getLastName() {
    		return lastName;
    	}
    	public void setLastName(String lastName) {
    		this.lastName = lastName;
    	}
    }
    Instead of including the .hbm in the hibernate.cfg.xml you would include the Person.java class. The @Id annotation specifies the key for the table that the object maps to. The other fields on the object are mapped by default to columns that correspond to their names i.e. firstName maps to the column FirstName. This can be overridden with the @Column(name=myColumn) annotation.

    Working through the hibernate tutorials provided in their distributions is really helpful for getting you used to what is going on and what needs to be done to configure hibernate correctly.

Similar Threads

  1. Hibernate, help me
    By Nick15 in forum JDBC
    Replies: 2
    Last Post: 06-05-2008, 03:39 PM
  2. Hibernate DAO
    By sundarjothi in forum Eclipse
    Replies: 0
    Last Post: 04-26-2008, 08:29 AM
  3. hibernate
    By vipinpvijayan in forum Web Frameworks
    Replies: 1
    Last Post: 04-21-2008, 05:41 PM
  4. Replies: 2
    Last Post: 06-30-2007, 03:01 PM
  5. Hibernate
    By Shuru in forum JDBC
    Replies: 2
    Last Post: 05-09-2007, 05:39 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •