|
Replies:
12
-
Pages:
1
-
Last Post:
Sep 17, 2008 5:11 PM
by: dan.j.allen
|
Threads:
[
Previous
|
Next
]
|
|
Posts:
5
From:
ny
Registered:
8/30/08
|
|
|
|
wrong column type for driving range -- "expected bit"
Posted:
Aug 31, 2008 4:36 PM
|
|
Still trying to work successfully through chapter 2. Hope I'm serving as a representative guinea pig, as well as simply a persistent nag. An experienced developer, without a whole lot of hands-on j2ee experience .
Using h2, jboss 4.2.3.GA, seam 2.0.2., java 1.6.0_07, microsoft vista.
I get this error in jboss.
17:02:00,519 INFO [TableMetadata] table found: H2.PUBLIC.FACILITY 17:02:00,535 INFO [TableMetadata] columns: [zip, phone, state, type, uri, drivi ng_range, city, country, id, price_range, address, county, description, name] 17:02:00,535 ERROR [[/open18]] Exception sending context initialized event to li stener instance of class org.jboss.seam.servlet.SeamListener org.jboss.seam.InstantiationException: Could not instantiate Seam component: ope n18EntityManagerFactory .... Caused by: javax.persistence.PersistenceException: org.hibernate.HibernateExcept ion: Wrong column type: DRIVING_RANGE, expected: bit at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Con figuration.java:720)
|
|
Posts:
5
From:
ny
Registered:
8/30/08
|
|
|
|
Re: wrong column type for driving range -- "expected bit"
Posted:
Sep 1, 2008 5:57 PM
in response to:
dazulay
|
|
I reverted to jboss 4.2.2.GA and seam 2.0.3, per the books suggestion. The problem still exists. Wrong column type for driving range.
I
|
|
Posts:
495
From:
Laurel, MD
Registered:
10/23/07
|
|
|
|
Re: wrong column type for driving range -- "expected bit"
Posted:
Sep 1, 2008 11:54 PM
in response to:
dazulay
|
|
Oh no, I accidently checked in a modified version of the schema. Driving range should have been disabled.
Here is the problem. It is actually between H2 and Hibernate. By default, Seam sets Hibernate to validate the schema when starting (hbm2ddl.auto=validate). But H2 and Hibernate don't agree on the signature of a boolean column (at the moment). Hence, you get this error.
There are two ways to work around the problem. First, you can comment out the line in the schema (etc/open18-initial-schema.sql) for DRIVING_RANGE. But if you want to see these boolean fields and how seam-gen deals with them (which definitely works) you can simply change hbm2ddl.auto to "update" (or "none") in resources/META-INF/persistence*.xml once the project is created.
We basically have to work around this problem in H2 as the moment (for as much as I like H2).
|
|
Posts:
495
From:
Laurel, MD
Registered:
10/23/07
|
|
|
|
Re: wrong column type for driving range -- "expected bit"
Posted:
Sep 2, 2008 12:04 AM
in response to:
dan.j.allen
|
|
I'm glad you brought this up, though, and I hope others will read this thread too. I personally don't like the hbm2ddl.auto=validate setting. I think it is really stupid that Hibernate attempts to validate the database schema (I'm not against a script performing this task) and I don't like that it is the default hbm2ddl.auto setting in seam-gen (I might end up changing it if the Seam lead agrees).
So, for anyone who is reading this, take note. After creating a project with seam-gen, change the hbm2ddl.auto setting to none or update (or even create or create-drop if that is what you want). If you don't want to change this setting every time you create a project, change it in the file in the Seam distribution that match this pattern.
seam-gen/resources/META-INF/persistence-{dev,prod}*.xml
Btw, I do recommend changing this in the book in chapter 2 and chapter 4. Hibernate and H2 don't agree over boolean column signatures, but who knows what other databases might turn up similar disagreements.
|
|
Posts:
5
From:
ny
Registered:
8/30/08
|
|
|
|
Re: wrong column type for driving range -- "expected bit"
Posted:
Sep 2, 2008 12:31 PM
in response to:
dazulay
|
|
Great! Fixed. Thanks, Dan, for the quick and detailed response.
|
|
Posts:
85
From:
El Segundo, CA
Registered:
6/9/08
|
|
|
|
Re: wrong column type for driving range -- "expected bit"
Posted:
Sep 2, 2008 12:57 PM
in response to:
dan.j.allen
|
|
That mismatch was part of what I had to deal with on my "real" project when I told it to make my CHAR(1) columns into hibernate yes_no entries. There, I had to remove the length test, too so the validator would work.
|
|
Posts:
85
From:
El Segundo, CA
Registered:
6/9/08
|
|
|
|
Re: wrong column type for driving range -- "expected bit"
Posted:
Sep 2, 2008 12:59 PM
in response to:
dan.j.allen
|
|
That mismatch was part of what I had to deal with on my "real" project when I told it to make my CHAR(1) columns into hibernate yes_no entries. There, I had to remove the length test, too so the validator would work.
|
|
Posts:
495
From:
Laurel, MD
Registered:
10/23/07
|
|
|
|
Re: wrong column type for driving range -- "expected bit"
Posted:
Sep 3, 2008 9:42 AM
in response to:
vgriffin
|
|
@vgriffin, the boolean problem is actually a separate issue (which I have a patch for and should apply soon). In the case of H2, there is a real boolean type, which Hibernate can use. The problem is that there is a bug in Hibernate's validate routine that mixes up the word "bit" with "boolean" and Hibernate simply complains that H2 is using the wrong type. If you turn off the validate, everything works perfectly.
As for your issue, basically, the reverse engineering process that seam-gen uses is a lot more intelligent than what we are currently taking advantage of. It is possible to be smarter about what annotations to use on each column. In my patch, if the database is oracle and the <sql-type> mapping in the reveng file is boolean, then the yes_no type annotation is added to the column. Oracle (and other databases) don't have a boolean type like H2 does. Thus, Hibernate has the ability to do a mapping from a Java boolean to a CHAR(1) y/n column.
What database are you using again?
|
|
Posts:
3
From:
Ocala, FL
Registered:
9/15/08
|
|
|
|
Re: wrong column type for driving range -- "expected bit"
Posted:
Sep 15, 2008 2:29 PM
in response to:
dan.j.allen
|
|
This information needs to go in the book's errata pages. That is where I first looked when things weren't going smoothly. At least link straight to your post where you describe how to change the hbm2ddl, and I suggest framing it in terms of paths that the books uses. E.g.,
You must change a setting in file /home/twoputt/projects/open18/resources/META-INF/persistence-%PROFILE%-war.xml...
You might save somebody's Sunday afternoon doing that. I'm just sayin'...
|
|
Posts:
495
From:
Laurel, MD
Registered:
10/23/07
|
|
|
|
Re: wrong column type for driving range -- "expected bit"
Posted:
Sep 15, 2008 3:31 PM
in response to:
thx01138
|
|
Technically this is not an errata issue because no where in the book do I talk about using the boolean type in H2 (truthfully this is a very unique feature of H2 since many databases don't have boolean types). What I need to do is publish a new snapshot of the source code, which I will do this week.
However, if you read on through the remainder of chapter 2, you would see that I instructed you to change hibernate.hbm2ddl.auto to "update" which would alleviate this issue. The bug is only in the schema validation routine. It does not affect how the application runs. You can definitely use boolean types with H2/Hibernate/Seam.
Sorry that this issue cost you time. Trust that I have burned tons of afternoons fixing bugs in the various Java projects, so I am no stranger to what a bug can do to wreck a weekend. Thanks to open source, I can contribute a patch and know that it will get fixed.
|
|
Posts:
495
From:
Laurel, MD
Registered:
10/23/07
|
|
|
|
Re: wrong column type for driving range -- "expected bit"
Posted:
Sep 15, 2008 3:44 PM
in response to:
dan.j.allen
|
|
Btw, if you want to do booleans in Oracle, here is what the property needs to look like:
private boolean excluded;
@Column(name = "EXCLUDED_YN", length = 1) @Type(type = "yes_no") public boolean isExcluded() { return this.excluded; }
public void setExcluded(boolean excluded) { this.excluded = excluded; }
If you want this annotation applied automatically during the seam-gen reverse engineering, see the following wiki page:
http://code.google.com/p/seaminaction/wiki/SeamGenEnhancements
|
|
Posts:
2
From:
Switzerland
Registered:
9/16/08
|
|
|
|
Re: wrong column type for driving range -- "expected bit"
Posted:
Sep 16, 2008 7:00 AM
in response to:
dazulay
|
|
Thanks for the explanation, saved me a lot of time too!
|
|
Posts:
495
From:
Laurel, MD
Registered:
10/23/07
|
|
|
|
Re: wrong column type for driving range -- "expected bit"
Posted:
Sep 17, 2008 5:11 PM
in response to:
pgruetter
|
|
> Thanks for the explanation, saved me a lot of time too!
I love hearing that.
|
|
|
Legend
|
|
Gold: 300
+
pts
|
|
Silver: 100
- 299
pts
|
|
Bronze: 25
- 99
pts
|
|
Manning Author
|
|
Manning Staff
|
|