Foros del Web » Programación para mayores de 30 ;) » Bases de Datos General »

hibernate

Estas en el tema de hibernate en el foro de Bases de Datos General en Foros del Web. Hola estoy empesando con hibernate y pues al ralizar mi primera aplicacion tengo algunos problemas, espero que alguien me pueda ayudar. la clase que tengo ...
  #1 (permalink)  
Antiguo 09/06/2010, 19:52
 
Fecha de Ingreso: junio-2010
Mensajes: 1
Antigüedad: 13 años, 10 meses
Puntos: 0
hibernate

Hola estoy empesando con hibernate y pues al ralizar mi primera aplicacion tengo algunos problemas, espero que alguien me pueda ayudar.

la clase que tengo es:


package example.productos;

public class Book {

private int id;
private String title;
private String author;

private String isbn;
private int pages;
private int copyright;
private float cost;
public Book() {
}
public void setId(int i) {
id = i;
}
public int getId() {
return id;
}
public void setTitle(String s) {
title = s;
}
public String getTitle() {
return title;
}
public void setAuthor(String s) {
author = s;
}
public String getAuthor() {
return author;
}
public void setIsbn(String s) {
isbn = s;
}
public String getIsbn() {
return isbn;
}
public void setPages(int i) {
pages = i;
}
public int getPages() {
return pages;
}
public void setCopyright(int i) {
copyright = i;
}
public int getCopyright() {
return copyright;

}
public void setCost(float f) {
cost = f;
}
public float getCost() {
return cost;
}
}

mis archivos de mapeo son

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="example.products.Book" table="books">
<id name="id"
type="int"
unsaved-value="0">
<generator class="hilo"/>
</id>
<property name="title"/>
<property name="author"/>
<property name="isbn" not-null="true"/>
<property name="pages" type="integer" column="pagecount" />
<property name="copyright"/>
<property name="cost">
<column name="cost" sql-type="NUMERIC(12,2)"/>
</property>
</class>
</hibernate-mapping>


y esta es la plicacion


package example.productos.book;

import java.io.*;
import org.hibernate.*;
import org.hibernate.cfg.*;

import example.productos.Book;

public class BookTest {

static SessionFactory sessionFactory;

public static void main(String [] args) {
try {
Configuration cfg = new Configuration().addClass(Book.class);
sessionFactory = cfg.buildSessionFactory();
Session session = sessionFactory.openSession();


//Session session = Config().SessionFactory().
//HibernateSession.currentSession();
Book book = new Book();
book.setTitle("Professional Hibernate");
book.setIsbn("003948490309");
book.setAuthor("Some Guys");
book.setPages(300);
book.setCost(29.99f);
session.save(book);
session.flush();
session.close();
} catch (Exception e) {
e.printStackTrace();
}
}




cuando ejecuto la aplicacion me mand un error el cual es el siguiente


9/06/2010 09:23:29 AM org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.5.0-Final
9/06/2010 09:23:29 AM org.hibernate.cfg.Environment <clinit>
INFO: loaded properties from resource hibernate.properties: {hibernate.connection.username=root, hibernate.connection.password=****, hibernate.dialect=org.hibernate.dialect.MySQL5Dial ect, hibernate.connection.url=jdbc:mysql://localhost:3306/products, hibernate.bytecode.use_reflection_optimizer=false, hibernate.connection.driver_class=com.mysql.jdbc.D river}
9/06/2010 09:23:29 AM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: Bytecode provider name : javassist
9/06/2010 09:23:29 AM org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
9/06/2010 09:23:29 AM org.hibernate.cfg.Configuration addClass
INFO: Reading mappings from resource: example/productos/Book.hbm.xml
9/06/2010 09:23:29 AM org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource: example/productos/Book.hbm.xml
org.hibernate.InvalidMappingException: Could not parse mapping document from resource example/productos/Book.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Config uration.java:641)
at org.hibernate.cfg.Configuration.addClass(Configura tion.java:688)
at example.productos.book.BookTest.main(BookTest.java :15)
Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from input stream
at org.hibernate.cfg.Configuration.addInputStream(Con figuration.java:610)
at org.hibernate.cfg.Configuration.addResource(Config uration.java:638)
... 2 more
Caused by: org.dom4j.DocumentException: null Nested exception: null
at org.dom4j.io.SAXReader.read(SAXReader.java:484)
at org.hibernate.cfg.Configuration.addInputStream(Con figuration.java:601)
... 3 more



espero me puedan ayudar saludos.

Etiquetas: hibernate
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 16:01.