-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Unsuccessful schema creation?!
PostPosted: Wed Oct 24, 2007 5:58 pm 
Newbie

Joined: Sat Oct 15, 2005 5:45 pm
Posts: 18
I have the a class called 'Game', 'User' and 'Category', but the Game table is not being created.

The debug from Hibernate is as follows...

22:32:09,667 DEBUG SchemaExport:303 - drop table if exists GAME_CATEGORY
22:32:09,699 DEBUG SchemaExport:303 - drop table if exists category
22:32:09,743 DEBUG SchemaExport:303 - drop table if exists game
22:32:09,749 DEBUG SchemaExport:303 - drop table if exists user
22:32:09,788 DEBUG SchemaExport:303 - create table GAME_CATEGORY (game_id bigint not null, category_id bigint not null unique, primary key (game_id, category_id))
22:32:09,864 DEBUG SchemaExport:303 - create table category (category_id bigint not null auto_increment, name varchar(255) unique, primary key (category_id))
22:32:09,931 DEBUG SchemaExport:303 - create table game (game_id bigint not null auto_increment, name varchar(255) unique, desc varchar(255), vis bit, price double precision, primary key (game_id))
22:32:09,932 ERROR SchemaExport:274 - Unsuccessful: create table game (game_id bigint not null auto_increment, name varchar(255) unique, desc varchar(255), vis bit, price double precision, primary key (game_id))
22:32:09,933 ERROR SchemaExport:275 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'desc varchar(255), vis bit, price double precision, primary key (game_id))' at line 1

The Game hibernate mapping file is straight forwards...

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

<class name="Game" table="game">

<id name="id" column="game_id">
<generator class="native"/>
</id>

<property name="name" type="string" column="name" unique="true"/>
<property name="description" type="string" column="desc"/>
<property name="visible" type="boolean" column="visible"/>
<property name="purchasePrice" type="double" column="price"/>

<set name="categories" table="GAME_CATEGORY">
<key column="game_id" />
<many-to-many column="category_id" unique="true"
class="Category" />
</set>

</class>
</hibernate-mapping>

And this is the class...

package com.ciderbob.common;

import java.util.Set;

/**
* This class represents a single game that is stored in the
* database system.
*
* @author Rob
*
*/
public class Game {

private Long id;
private String name;
private String description;
private boolean visible;
private Double purchasePrice;
private Set<Category> categories;

/**
* @param name
* @param description
* @param visible
* @param purchasePrice
* @param categories
*/
public Game(String name, String description, boolean visible,
Double purchasePrice, Set<Category> categories) {
this.name = name;
this.description = description;
this.visible = visible;
this.purchasePrice = purchasePrice;
this.categories = categories;
}

// Private for Hibernate
private Game() {
}

/**
* @return the id
*/
public Long getId() {
return id;
}
/**
* @param id the id to set
*/
private void setId(Long id) {
this.id = id;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the description
*/
public String getDescription() {
return description;
}
/**
* @param description the description to set
*/
public void setDescription(String description) {
this.description = description;
}
/**
* @return the visible
*/
public boolean isVisible() {
return visible;
}
/**
* @param visible the visible to set
*/
public void setVisible(boolean visible) {
this.visible = visible;
}
/**
* @return the purchasePrice
*/
public Double getPurchasePrice() {
return purchasePrice;
}
/**
* @param purchasePrice the purchasePrice to set
*/
public void setPurchasePrice(Double purchasePrice) {
this.purchasePrice = purchasePrice;
}
/**
* @return the categories
*/
public Set<Category> getCategories() {
return categories;
}
/**
* @param categories the categories to set
*/
public void setCategories(Set<Category> categories) {
this.categories = categories;
}

}

Would anyone be able to tell why it fails to generate the table? I've tried renaming the 'visible' property, I also used to use BigDouble and changed it to Double because I thought that was the problem.

Later when doing a query I also get told that I have something wrong with the mysql syntax, but the table doesn't even exist.

I think I have missed something trivial, my test that I am running is this...

Set<Category> game1Cats = new HashSet<Category>();
game1Cats.add(new Category("Category1"));
game1Cats.add(new Category("Category2"));
Game game = new Game("Game1","This is game 1",true,new Double(9.99), game1Cats);
session.saveOrUpdate(game);

// Now check the game exists and that when
// retrieved back out of the database it contains
// the two categories
Criteria criteria = session.createCriteria(Game.class);
criteria.add(Expression.eq("name", "Game1"));
List results = criteria.list();
assertEquals(results.size(),1);
Game retrievedGame = (Game) results.get(0);
assertEquals("Game1", retrievedGame.getName());
assertEquals(2, retrievedGame.getCategories().size());

// Then perform a query for all categories, check that
// Category1 and Category2 exists.
criteria = session.createCriteria(Category.class);
criteria.add(Expression.eq("name", "Category1"));
results = criteria.list();
assertEquals(1, results.size());
criteria.add(Expression.eq("name", "Category2"));
results = criteria.list();
assertEquals(1, results.size());
criteria.add(Expression.eq("name", "Category3"));
results = criteria.list();
assertEquals(0, results.size());

Any help / pointers will be appreciated,
Cheers.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.