ejuarros (6) [Avatar] Offline
#1
I am having problems with the many-to-many relation between tags and courses (at the moment of creating a tag) in the coursemanager generated app copy/pasting from the book. Is there a coursemanager.roo script available?
Thanks.
MikB (202) [Avatar] Offline
#2
Re: coursemanager.roo script
Have you checked out the source code at https://github.com/krimple/spring-roo-in-action-examples/?

I don't think there's a coursemanager.roo per se, but useful to investigate if you haven't already. What seems to be your problem more specifically?
ejuarros (6) [Avatar] Offline
#3
Re: coursemanager.roo script
MikB,
thank you for answering. After creating two course entity instances and I try to create a tag (set Tag, Description and select a Course), at the saving I get

HTTP Status 400 -
type Status report
message
description The request sent by the client was syntactically incorrect ().
Apache Tomcat/6.0.29

The script that i am using is listed below.
Rgds.


project --topLevelPackage com.t.coursemanager --java 6 --projectName coursemanager
jpa setup --provider HIBERNATE --database HYPERSONIC_PERSISTENT
database properties set --key database.url --value jdbc:hsqldb:file:coursemanager;shutdown=true

enum type --class ~.model.CourseTypeEnum
enum constant --name SEMINAR
enum constant --name CREDIT
enum constant --name CONTINUING_EDUCATION

entity jpa --class ~.model.Course --testAutomatically
field string --fieldName name --sizeMin 1 --sizeMax 60 --column course_name
field string --fieldName description --notNull --sizeMax 1000
field number --fieldName listPrice --type java.math.BigDecimal --decimalMin 0.0 --decimalMax 99999.99 --digitsFraction 2 --digitsInteger 5 --notNull
field number --fieldName maximumCapacity --type java.lang.Integer --min 1 --max 9999 --notNull --column max_capacity
field date --fieldName runDate --type java.util.Date --dateTimeFormatPattern MM/dd/yyyy
field enum --fieldName courseType --type ~.model.CourseTypeEnum --enumType STRING --notNull

entity jpa --class ~.model.TrainingProgram --testAutomatically
field string --fieldName name
field set --fieldName courses --type ~.model.Course --cardinality ONE_TO_MANY --mappedBy trainingProgram

focus --class ~.model.Course
field reference --fieldName trainingProgram --type ~.model.TrainingProgram --cardinality MANY_TO_ONE

entity jpa --class ~.model.Tag --testAutomatically
field string --fieldName tag --sizeMin 1 --sizeMax 25 --notNull
field string --fieldName description --sizeMax 250 --notNull
field set --fieldName courses --type ~.model.Course --cardinality MANY_TO_MANY

focus --class ~.model.Course
field set --fieldName tags --type ~.model.Tag --cardinality MANY_TO_MANY --mappedBy courses

entity jpa --class ~.model.Person --abstract --inheritanceType TABLE_PER_CLASS
field string --fieldName firstName --sizeMax 30
field string --fieldName middleNameOrInitial --sizeMax 30
field string --fieldName lastName --sizeMax 30
field string --fieldName addressLine1 --sizeMax 30
field string --fieldName addressLine2 --sizeMax 30
field string --fieldName city --sizeMax 30
field string --fieldName stateCode --sizeMax 30
field string --fieldName postalCode --sizeMax 30
field string --fieldName emailAddress --sizeMax 30

entity jpa --class ~.model.Student --extends ~.model.Person --testAutomatically

entity jpa --class ~.model.Instructor --extends ~.model.Person --testAutomatically

json all --deepSerialize
web mvc json setup
web mvc json all

web mvc setup
web mvc all --package ~.web
web mvc finder all

web mvc language --code de
web mvc language --code es

perform package
quit
MikB (202) [Avatar] Offline
#4
Re: coursemanager.roo script
Unfortunately I don't have the time to look at your project just now, but I would have started anew, building one part at a time writing my own tests part by part, saving to my versioning system after each green test, until I got the error.

The problem with Roo is that it makes so much parts for you — which is to a large degree a good thing — that you have to keep track of and there's really no alternative than to get to know each part a little bit at least.

The best way to do that is to make everything as basic as possible, building the system part by part and write test cases for every stage.

That said glazing over I would drop all special Annotations and all fields not related to the relationship between your objects. Then go from there.

My personal coursemanager.roo file has the same relationships as yours. I'm reluctant to post it before I can verify it. I have had great problems with the source code of this title (as I'm on jdk1.5 I think), so I have several versions. Maybe tomorrow.
ken.rimple (246) [Avatar] Offline
#5
Re: coursemanager.roo script
I think this is the problem where you name a field lowercase 'tag' - also I switched to @Length as opposed to @Size - t was trying to take the tag field and convert it to a number and failing.
MikB (202) [Avatar] Offline
#6
Re: coursemanager.roo script
I always start my field names with a small letter and use camel case for following words in the name. That is the convention as I understand it.
ejuarros (6) [Avatar] Offline
#7
Re: coursemanager.roo script
Thank you for answering. I think that the problem was the tag fieldName in the class ~.model.Tag.
The script below works creating the COURSE, TAG and TAG_COURSES tables.
Rgds.

// Course >----< Tag
project --topLevelPackage com.t.e5 --java 6 --projectName e5
jpa setup --provider HIBERNATE --database HYPERSONIC_PERSISTENT
database properties set --key database.url --value jdbc:hsqldb:file:e5

entity jpa --class ~.model.Course --testAutomatically
entity jpa --class ~.model.Tag --testAutomatically

focus --class ~.model.Course
field string --fieldName name --sizeMin 1 --sizeMax 60 --column COURSE_NAME

focus --class ~.model.Tag
field string --fieldName name --sizeMin 1 --sizeMax 25 --notNull
field set --fieldName courses --type ~.model.Course --cardinality MANY_TO_MANY

focus --class ~.model.Course
field set --fieldName tags --type ~.model.Tag --cardinality MANY_TO_MANY --mappedBy courses

web mvc setup
web mvc all --package ~.web
web mvc finder all

perform package
MikB (202) [Avatar] Offline
#8
Re: coursemanager.roo script
OK, so the problem was that you used "tag", not that it was lower case? You replaced this with "name", correct?
ejuarros (6) [Avatar] Offline
#9
Re: coursemanager.roo script
That's right.
MikB (202) [Avatar] Offline
#10
Re: coursemanager.roo script
Well, I use "tag" as the String field name of my Tag class. I don't have this problem of yours. Something is missing from your and Kens observations. Or I misinterpret what you're saying.
MikB (202) [Avatar] Offline
#11
Re: coursemanager.roo script
Here's an excerpt of my longer coursemanager.roo script that I ran with Roo1.2m1 and imported into STS 2.8.1.RELEASE as a maven project, allowing maven dependency updates, added jaxb explicitly and cleaned and rebuilt successfully.

Then I run all basic tests successfully under jdk1.5. As you see I use MySQL here.

coursemanager.roo excerpt:
project --topLevelPackage org.rooina.coursemanager --projectName coursemanager_ch5
//Create this db with the user assigned the proper permissions prior to running the script or change database below
jpa setup --database MYSQL --provider HIBERNATE --databaseName coursemanager_web --userName sa
//actually I didn't use "jpa". Updated it for your convenience.
entity jpa --class ~.model.Course --testAutomatically

entity jpa --class ~.model.Tag --testAutomatically
field string --fieldName tag --sizeMin 1 --sizeMax 25 --notNull
field string --fieldName description --sizeMax 250 --notNull
field set --fieldName courses --type ~.model.Course --cardinality MANY_TO_MANY

focus --class ~.model.Course
field set --fieldName tags --type ~.model.Tag --cardinality MANY_TO_MANY --mappedBy courses
ejuarros (6) [Avatar] Offline
#12
Re: coursemanager.roo script
I have changed
focus --class ~.model.Tag
field string --fieldName name --sizeMin 1 --sizeMax 25 --notNull

by
focus --class ~.model.Tag
field string --fieldName tag --sizeMin 1 --sizeMax 25 --notNull

in the script and the problem has appeared.
MikB (202) [Avatar] Offline
#13
Re: coursemanager.roo script
To me that doesn't make sense yet, unless you use "tag" somewhere else and the reference is ambiguous or something. My main point is that "tag" should be a legal name for a field.

Why do you think this problem happen in the first place?

I guess I have to run your script in order to find out. It doesn't happen in mine.

Anyways this is my resulting Course.java:
//imports and package omitted
public class Course {
//trainingProgram omitted
@ManyToMany(cascade = CascadeType.ALL, mappedBy = "courses")
private Set<Tag> tags = new HashSet<Tag>();
// offerings omitted
}

and my Tag.java:
//imports and package omitted
public class Tag {
@NotNull
@Size(min = 1, max = 25)
private String tag;
//field description omitted
@ManyToMany(cascade = CascadeType.ALL)
private Set<Course> courses = new HashSet<Course>();
}
ken.rimple (246) [Avatar] Offline
#14
Re: coursemanager.roo script
Try renaming the variable as "name". Sounds weird but it worked for me. I have been trying to figure out why. Also with your script I am getting a numerical validation stack trace as it tries to convert the description field to a number to create a tag.
MikB (202) [Avatar] Offline
#15
Re: coursemanager.roo script
I posted my complete coursemanager.roo script at pastebin:
http://pastebin.com/vF5K7iYG

Tested on jdk1.5 with Roo 1.2m1, but should work on 1.6 and later with Roo 1.2.x unless I'm mistaken.
As you can see I use "tag" as the name in my Tag class and there isn't and shouldn't be a problem with this.
ejuarros (6) [Avatar] Offline
#16
Re: coursemanager.roo script
the issue appears when saving a record with a field with same name (in lower case) as the class:
focus --class ~.model.Course
field string --fieldName course --sizeMin 1 --sizeMax 60 --column COURSE_NAME

HTTP Status 400 -
type Status report
message
description The request sent by the client was syntactically incorrect ().
Apache Tomcat/6.0.29
ken.rimple (246) [Avatar] Offline
#17
Re: coursemanager.roo script
My theory is that the type converters are generated erroneously when a field has the same name as the entity. I have to pick it apart, but I smell a JIRA.
ken.rimple (246) [Avatar] Offline
#18
Re: coursemanager.roo script
Theory blown. In fact, I have a new one, and it was so complex that I figured it would be better suited on my blog.

Short answer - I think Roo wants to convert the nested 'tag' as a full-blown tag object, so it wants to take it as an ID, run it through idToTagConverter, and that's where it's failing. But only if you have a Tag with a property with the name of tag on it. I've verified this. Here is the updated project with my verifying Tag converter tests attached.

MikB and others - I am buried this week catching up after training for two weeks, but if any of you want to take on the challenge here and see what's to do, here is my blog entry on the subject:

http://www.rimple.com/tech/2012/5/6/dont-call-names-roos-tag-with-a-tag-problem.html
carcarx (74) [Avatar] Offline
#19
Re: coursemanager.roo script
Has anyone made a coursemanager.roo script that includes the Offering class as per the updated source code?

Thanks!