Spring Roo Oracle and Underscore - oracle

I have a question concerning spring roo and databases.
I have a field called personName, in oracle to column is create as person_Name
I there a way to avoid the underscore. I suppose naming my column personname would fix this, but can I ask spring not to add the underscore ?

If you need a general solution (instead of "fixing" some single points (abaloghs answer)), you can specify a Naming Strategy for your JPA provider.
For an example see: JPA (Hibernate) and custom table prefixes

Roo by default refers to the JPA implementation to determine column names. You can override the defaults with the --column property:
entity --class Foo
field string --fieldName FooBar --column fooBar

Bonjour,
by the way, I do not think that it is possible to reverse engineer a database with underscores in table names :
the corresponding domain classes will be created and compiled since Java accept undersocres in class names
the tests will be performed without raising any issue
everything will be scaffold for the GUI
you will succesfully deploy it on tomcat and your application page will show up in your browser
You may fill the form to create a new instance of your object
But if you click on SAVE --> internal error
If you have a look at the tomcat log, you will fid the well known exception : javax.servlet.jsp.JspTagException: No message found under code ...
The reason is that your class name has been truncated in the message_xx.properties files.
Everything before the underscore is dropped and thus, no message is found in order to display that your record has been successfully saved.
It would be nice that the ROO shell raise an error when the jpa entity is created and not at runtime ...

Related

How to use Custom table name for Quartz tables in spring boot

I am using quartz with spring boot 2.x. Can I use custom table names and custom column names for the given quartz tables? I can prefix, but my requirement is to change the name of the table.
If yes, then how can I keep the sync.
Ex: instead of qrtz_JOB_DETAILS (qrtz_ is prefixed here), can I create a table as qrtz_myorg_jobDetails?
That cannot be done out of the box.
All table names are in constants class in jdbcjobstore package
https://www.quartz-scheduler.org/api/2.1.7/org/quartz/impl/jdbcjobstore/Constants.html

Spring-data-jdbc - How to set schema in many-to-many relationship

I am following the spring.io blog here: https://spring.io/blog/2018/09/24/spring-data-jdbc-references-and-aggregates and have a sample SpringBoot app with Book and Author entities here: https://github.com/b-sridhar/spring-data-jdbc-example.
I get the following error: No value supplied for the SQL parameter 'demobook': No value registered for key 'demobook'
And while debugging noticed the SQL query that is executed is: INSERT INTO demo.book_author (author, demo.book) VALUES (:author, :demobook) which should have been INSERT INTO demo.book_author (author, book) VALUES (:author, :book). This happens because I have the #Table("demo.book") as the annotation for the Book entity. If I remove the demo schema in the table name then the tests in BookAndAuthorsTests go through fine.
How to set the schema for the table Book?
This is a bug in the 1.0.x release. It is fixed for 1.1.
If you upgrade your spring-boot-starter-parent to 2.2.0.M5 you'll get the spring-data-jdbc version 1.1.0.RC2 which contains the fix.
With that fix table names in #Table annotations do work as well as the approach of having the NamingStrategy return a schema.
Note: that your configuration then needs to extend AbstractJdbcConfiguration instead of JdbcConfiguration.
Another note: Your example project then chokes because the AuthorRef needs an explicit mapping to the table BOOK_AUTHOR.
I'll leave a PR in a second.

How do I use Spring Roo for referenced data

I’m new to Spring Roo and looking to build an application. I need to have combo boxes to select values into string fields – a fairly common requirement. The Spring Roo Pizza example shows this using enumerated data types enum constant, but I require the source values to be editable by an admin (ie in a table) so we can change the values in the future. Further, my preference would be to use a single table to contain all these lists for easier maintenance.
I know the SQL I want to generate the list would be something like:
Select listvals FROM listTable WHERE listtype = “status”;
Then, my dropdown box would show something like: Active, Inactive. The user would select one, and the string “Active” would be stored in the target field.
And in a second example, we might use:
Select listvals FROM listTable WHERE listtype = “State”;
The second dropdown box would show something like: Alaska, California, Florida. The user would select one, and the string “Florida” would be stored in the target field.
My CORE question is how does one achieve this sort of function in Roo?
Using the Pizza Shop quick start as a sandbox I have tried defining the target fields such as:
I changed: field reference --fieldName base --type ~.domain.Base to:
field reference --fieldName base --type ~.domain.Base --referencedColumnName name
Which returned this error:
#JoinColumn name is required if specifying a referencedColumnName
The initial problem is that at this point roo has yet to create the row ID columns for the db, so I don’t know the name of the join column on the Base table. But, if I wait until after I run the script with a 1:M join, the column pizza.base will be defined as an integer, and not the string that I want.
So, I ran the vanilla pizza shop roo script and interrogated the vanilla db. (Does roo generate an SQL script for db creation that I could look at?)
As it turns out, roo names the row id column “id” as a BigInt. (I also note that it doesn't seem to make use of the SEQUENCE feature that postgres recommends for primary indices / row Ids.)
So now I run:
field reference --fieldName base --type ~.domain.Base --referencedColumnName name --joinColumnName id
Roo likes this!
Until I perform tests where it throws out a number of undecipherable errors in the Surefire reports.
I note that solving this problem is only step 1 to meeting my overall requrement described above. Step 2 will be to try to inject some sort of filter or where clause into the reference statement. I suspect that this has to do with the --fetch option (Roo support docs (http://docs.spring.io/autorepo/docs/spring-roo/1.2.5.RELEASE/reference/html/command-index.html#command-index-finder-commands - The fetch semantics at a JPA level; no default value)
But, I can’t find an example of this to see if I’m on the right track or to model my ‘fetch semantics’ – whatever those are.
Another possibility might be to use field list to define a class containing my list of dropdown values. This has a similar modifier --fetch, but again I can’t find any examples.
I’d really appreciate some help in answering my CORE question above.
THANKS!
Fetch parameter indicates whether the association should be lazily loaded or must be eagerly fetched (https://docs.oracle.com/javaee/6/api/javax/persistence/ManyToOne.html#fetch()).
Maybe the error of tests can be because you try to find, create, delete or update elements with related elements that not exists. Check this first of all.
You can see an example of application created with gvNIX (distribution of Spring Roo) that contains relationships between some entities on https://github.com/DISID/gvnix-samples/blob/master/quickstart-app/quickstart.roo

Spring Roo Web MVC Insert - No Default Primary Key

I have a web MVC project generated by Spring roo. I reverse engineered a MSSQL DB and have the need to create my own primary keys but am unable to insert using the inputs Roo generated (anticipates an auto increment or self-generated ID). Any ideas? I recieve the below message from the console when I attempt this.
ERROR org.hibernate.util.JDBCExceptionReporter - Field 'id' doesn't have a default value
It appears that the DBRE code generation for #ManyToOne/#JoinColumn is a bit incorrect. The code generator incorrectly sets such a field with "insertable = false" which then omits this particular foreign key column reference during an insert into the referencing table. Change it to "insertable = true" as well as the "updateable" if you require and you should be good.

Adding columns to DB after publishing using EF CodeF and mvc nugget Scaffold

I have created a web site using mvc 3 and Ef code first , now after publishing the site and it's DB I have found out that I need to add a new columns to one of my DB table,
(the DB already has a lot of data in it )
should I add the columns direct to the DB or should I add to the class?
(just a simple string with get and set)
And how can I do it without losing my data in the DB ?
thanks
Adding the columns to the class should be enough. Evidence you can find here.
Here is the full list of changes that migrations can take care of automatically:
Adding a property or class
Nullable columns will be assigned a value of null for any existing rows of data
Non-Nullable columns will be assigned the CLR default for the given data type for any existing rows of data
Renaming a property or class
See ‘Renaming Properties & Classes’ for the additional steps required here
Renaming an underlying column/table without renaming the property/class
(Using data annotations or the fluent API)
Migrations can automatically detect these renames without additional input
Removing a property
See ‘Automatic Migrations with Data Loss’ section for more information
I suggest you to add the columns direct to the DB and to the class, and test it on the local machine.

Resources