On this one project I develop on Windows and deploy on Linux, and use mysql as database.
Because of the filesystem nature, table names (and more, I suppose) are case insensitive on windows, and sensitive on *nix [Ref]
Problem is, by default play/jpa uses the same name as the java model class for the table (so it is capitalized, eg. UserProfile). When I dump my windows mysql database it dumps lowercase table names.
Which means I can't import them in Linux because of the case sensitivity.
Is there a way to tell Play / JPA to always use lowercase names for the models?
Or must I set a #Table(name="userprofile") annotation on any single model?
You need to use a different naming strategy for hibernate. There is an improved NS available with hibernate
http://docs.jboss.org/hibernate/orm/3.6/javadocs/org/hibernate/cfg/ImprovedNamingStrategy.html
you can simply add this line to application.conf
hibernate.ejb.naming_strategy=org.hibernate.cfg.ImprovedNamingStrategy
Look also at this post and at this SO question
Related
I want to name my mysql table column names using camel case and create php classes from these mysql tables with the same camel case names. I will be generating these php classes automatically. I'm wondering if I can rely on column name case no matter what platform I run my application on. So for example, if I name one column name "FirstName", will I ever encounter a time where reading the column name from the database will product "firstname" or something like that?
Short answer is no.
The long answer is that case-sensitivity for some things in MySQL depend on the underlying operating system. (Unix being the sensitive one)
Here is the reference to the issue in the MySQL documentation.
Consequently, the case sensitivity of the underlying operating system plays a part in the case sensitivity of database and table names. This means database and table names are not case sensitive in Windows, and case sensitive in most varieties of Unix. One notable exception is Mac OS X, which is Unix-based but uses a default file system type (HFS+) that is not case sensitive.
Also from the documentation on column names specifically:
Column, index, and stored routine names are not case sensitive on any platform, nor are column aliases. Trigger names are case sensitive, which differs from standard SQL.
MySQL is case sensitive in table and column names, and case in-sensitive in keywords.
But note that Windows is only case preserving, and file names are table names. (If you work on table "SalesAccounts" when you meant "Salesaccounts" then it will read OK on Windows and fail on Linux.
You should be OK with what you want to do, but
1) Test on Linux,
2) Test the tools you are using.
Back when I started with database design, for some reason it was recommended that you always use snake case (my_table_name) for tables and columns. I think this was especially true in MySQL. The reasoning was there were instances where capitalization would be lost or enforced. Flash forward to today and I see a lot of people using Pascal Case ("MyTableName"), which I would prefer.
Is there any reason to still use snake case for table and column names? Are there any instances where capitalization could be lost or enforced (say if changing database engines, OS's, etc.)?
SQL is case-insensitive. Many databases fold names to lowercase when creating tables, so capitalisation is lost.
The only portable way to preserve "words" within names is to use snake case.
from http://dev.mysql.com/doc/refman/5.0/en/identifier-case-sensitivity.html:
"In MySQL, databases correspond to directories within the data directory. Each table within a database corresponds to at least one file within the database directory (and possibly more, depending on the storage engine). Consequently, the case sensitivity of the underlying operating system plays a part in the case sensitivity of database and table names. This means database and table names are not case sensitive in Windows, and case sensitive in most varieties of Unix. One notable exception is Mac OS X, which is Unix-based but uses a default file system type (HFS+) that is not case sensitive."
In short, it depends on the filesystem underneath the database.
Nowadays, most mysql servers run on linux systems which have an ext3/ext4/bttrfs/namesomeother filesystem which are case sensitive. FAT12, for example, was not case sensitive and not even case preserving, so the database MyDB may not be found by mysql after creation. Fat32 and HFS+ are not case sensitive, but it is case preserving; so you can get into trouble with Mydb and myDB.
So if you know your database may be hosted on a FAT12 system, you may still want to make sure you watch case.
SQL is case insensitive, unless you are using delimited identifiers. The example above compares a normal identifier with a delimited one. Identifier rules go out the window when using delimited identifiers; this is a valid identifier "4argo ###$# yourself".
Words strung together are harder to read than words separated, and they are more prone to spelling errors, especially if plurals are sometimes involved.
Delimited identifiers allow you to mimic case-sensitive application languages, but they can cause difficulties in things like metadata searches. You can easily end up with vendor-specific behavior, which is an obvious pain.
Some DBMS were implemented before SQL was standardized to fold to uppercase; they will never change. (My guess is IBM won an argument at some meeting and made it uppercase.) And, they should not have to, as long as case insensitivity is handled correctly.
It's a bad idea to model your schema based on how the particular DBMS you are using is implemented.
I'm trying to setup my hibernate entity to auto create the table IFAS_util_max_object_v in that exact format. No matter what I try, I can't seem to get it to capitalize IFAS. Does anybody have any ideas?
This is what I've tried.
#Table(name="\"IFAS_util_max_object_v\"")
Also, I'm using mysql db.
What operating system are you using?
Mysql has a setting in the configuration file to determine if table names should be converted to lower case. As the tables correspond to files on the disk with the table name they are converted to lower case when using Windows as Windows file names are case insensitive. So it is impossible when using Windows.
You can read here about the details.
I imported a database from Windows to linux and all the tables names are in lowercase.
Is there a way to convert the mysql table names form lowercase to uppercase in linux?
Thanks a lot for any suggestion provided.
I am assuming you are addressing the table names in uppercase, which worked in Windows but no longer works on Linux because of case sensitivity.
You could rename each database. However, if you have access to the mySQL configuration, you should also be able to set --lower-case-table-names to 1.
I have no experience with the option, but according to the manual, it makes mySQL behave case-insensitively towards tables, as it does by default on Windows.
I have a a problem whereby my production server runs Unix and my dev server runs MS Windows.
The problem is that Windows is not case sensitive and Unix is. So my table set on the production server uses Uppercase table names ie "Customers" and on Windows the table names are in lowercase "customers".
All this is fine until you need to get data from one box to another and your SQL export says insert into "customers" in lowercase, and presto "Unkown table customers". Because the production server is currently on a shared hosting plan i cant change the settings and install the key that ignores case.
So my question, is there a way to get Windows to convert the tables back to the correct case or is there some setting I can include in the export SQL file so that i can upload data without this problem.
Thanks
UPDATE
Here is what I discovered for anybody else having this issue.
If you have already set up your tables running MySQL on Windows adding
lower_case_table_names=2 to your my.cnf or my.ini file will not change the case of your tables automatically even if they were originally created using uppercase or mixed case names.
CREATE TABLE "MyTable" will create a new table "mytable" not "MyTable" even when lower_case_table_names=2 is set in your my.cnf file.
To get around this problem use this method
Make a copy of your original table
Drop your original table
Rename your copy table using the correct case.
This is the only way it will work. Hope this helps somebody.
Taken from dev.mysql.com:
To avoid data transfer problems arising from lettercase of database or table names, you have two options:
Use lower_case_table_names=1 on all systems. The main disadvantage with this is that when you use SHOW TABLES or SHOW DATABASES, you do not see the names in their original lettercase.
Use lower_case_table_names=0 on Unix and lower_case_table_names=2 on Windows. This preserves the lettercase of database and table names. The disadvantage of this is that you must ensure that your statements always refer to your database and table names with the correct lettercase on Windows. If you transfer your statements to Unix, where lettercase is significant, they do not work if the lettercase is incorrect.
Exception: If you are using InnoDB tables and you are trying to avoid these data transfer problems, you should set lower_case_table_names to 1 on all platforms to force names to be converted to lowercase.
If you plan to set the lower_case_table_names system variable to 1 on Unix, you must first convert your old database and table names to lowercase before stopping mysqld and restarting it with the new variable setting.
There is one easy solution:
Always name your tablenames lowercase.
The universal guiding philosophy of Windows with respect to case is "case-insensitive, case stored". That means Windows never intends to discard your case, so it's a little mysterious why your tables on Windows are lower-case.
Apologies if this is a dumb question, but have you tried renaming the tables on the Windows machine so they have the correct case pattern?