This is my xml configuration:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "mybatis-generator-config_1_0.dtd">
<generatorConfiguration>
<context id="DB2SAMPLE" defaultModelType="flat" targetRuntime="MyBatis3">
<plugin type="org.mybatis.generator.plugins.RenameExampleClassPlugin">
<property name="searchString" value="Example$"/>
<property name="replaceString" value="Criteria"/>
</plugin>
<plugin type="org.mybatis.generator.plugins.CaseInsensitiveLikePlugin" />
<plugin type="org.mybatis.generator.plugins.RowBoundsPlugin" />
<commentGenerator>
<property name="suppressAllComments" value="true" />
</commentGenerator>
<jdbcConnection driverClass="com.ibm.db2.jcc.DB2Driver" connectionURL="jdbc:db2://LOCALHOST:50000/mydb" userId="username" password="password">
</jdbcConnection>
<javaModelGenerator targetPackage="foo.package" targetProject="src/main/java">
<property name="enableSubPackages" value="true" />
<property name="trimStrings" value="false" />
</javaModelGenerator>
<sqlMapGenerator targetPackage="foo.package" targetProject="src/main/resources">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator>
<javaClientGenerator type="XMLMAPPER" targetPackage="foo.package" targetProject="src/main/java">
<property name="enableSubPackages" value="true" />
</javaClientGenerator>
<table schema="SCHEMA" tableName="MyTable" alias="MYTABLE" domainObjectName="MYTABLE"/>
</context>
</generatorConfiguration>
The problem is that it not found the table MyTable because it search MYTABLE.
How can I setup MyBatis generator for searching case sensitive name MyTable?
Thanks.
From https://www.codeday.top/2016/12/22/6853.html
1, If schema,catalog or tablename There are spaces in , So what format is set , On the exact use of the specified format to query ;
2, otherwise , If the database identifier uses uppercase , that MBG Automatically turn table name into uppercase search ;
3, otherwise , If the database identifier uses lowercase , that MBG Automatically turn table name to lowercase search ;
4, otherwise , Query using the specified case format ;
Additional , If the table is created , Using "" Specify database object size , Even if the database identifier is used , In this case a table name is created using a given case size ;
At this time , Please set delimitIdentifiers="true" Case preserving format ;
Related
If I put "<commentGenerator>" after "<jdbcConnection>", MBG proposed an error that context content should match: blablabla...
But when I put "<commentGenerator>" before "<jdbcConnection>", everything is ok. Here I have something to complain to the official website that if the order of these items is need, why you do not tell us! What an important thing! You r kidding the freshmen. Maybe it is some where I do not know, but this is a key point to build the MBG's configuration file successfully, why not put this NOTE on the top of the tutorial or somewhere eye-catching?
<generatorConfiguration >
<classPathEntry location="D:\mariadb-java-client-1.1.7.jar" />
<context id="db" >
<commentGenerator>
<property name="suppressAllComments" value="true" />
<property name="suppressDate" value="true" />
</commentGenerator>
<jdbcConnection driverClass="org.mariadb.jdbc.Driver"
connectionURL="jdbc:mariadb://localhost:3306/dbname"
userId="root"
password="password"
/>
<javaTypeResolver >
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<!-- Model Class -->
<javaModelGenerator targetPackage="org.infrastructure.model" targetProject="infrastructure\src\main\java">
<property name="enableSubPackages" value="false" />
<property name="trimStrings" value="true" />
</javaModelGenerator>
<!-- XML Files -->
<sqlMapGenerator targetPackage="sqlMap" targetProject="infrastructure\src\main\config">
<property name="enableSubPackages" value="false" />
</sqlMapGenerator>
<!-- DAO -->
<javaClientGenerator type="XMLMAPPER" targetPackage="org.infrastructure.dao" targetProject="infrastructure\src\main\java">
<property name="enableSubPackages" value="false" />
</javaClientGenerator>
<!-- Tables -->
<table tableName="user" domainObjectName="User" ></table>
</context>
</generatorConfiguration>
First of all, in your xml configuration file, it doesn't contains a valid root element, which always should be like <!DOCTYPE .../>. About how to add a correct root element of mybatis generator configuration file, please see example from MyBatis GeneratorXML Configuration File Reference.
If you correctly specified root element such as following:
<!DOCTYPE generatorConfiguration PUBLIC
"-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd"
>
This root element contains a typical DTD declaration located at http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd. This is the definition of the order of these items is need. And we are going to see what it looks like.
From line 47 of this document type definition, it defines element named context. The content is as following:
<!--
The context element is used to describe a context for generating files, and the source tables.
-->
<!ELEMENT context (property*, plugin*, commentGenerator?, jdbcConnection, javaTypeResolver?,javaModelGenerator, sqlMapGenerator?, javaClientGenerator?, table+)>
Which obviously defined the order of the element in context, that is:
property*, plugin*, commentGenerator?, jdbcConnection,
javaTypeResolver?,javaModelGenerator, sqlMapGenerator?,
javaClientGenerator?, table+
In this element, all children must occurs as following rules:
+ for specifying that there must be one or more occurrences of the item — the effective content of each occurrence may be different;
* for specifying that any number (zero or more) of occurrences is allowed — the item is optional and the effective content of each occurrence may be different;
? for specifying that there must not be more than one occurrence — the item is optional;
If there is no quantifier, the specified item must occur exactly one time at the specified position in the content of the element.
After we understanding its real meaning, why you could not change the order of commentGenerator and jdbcConnection should be clear.
Maybe you want to know how to make the element out of order, question How to define DTD without strict element order could be useful.
Wish it helpful.
I have an EDMX (Entity Framework 6.1.3) that I'm using to query two different databases. There are some minor differences between the databases but I only want the common columns. I generated the EDMX from Database A, and removed the columns that were not in Database B from the Diagram and regenerated the code.
If I query database B the query contains the columns I removed, although the final SELECT does not. This means that the query fails.
The table mapping shows the columns, but with nothing on the Value/Property side:
The exception is:
System.Data.Entity.Core.EntityCommandExecutionException : An error occurred while executing the command definition. See the inner exception for details.
----> System.Data.SqlClient.SqlException : Invalid column name 'ValidFromDate'.
Invalid column name 'ValidToDate'.
Invalid column name 'LastPulled'.
Invalid column name 'IsCurrent'.
The query that is being sent to the server is:
SELECT TOP (1)
[c].[FirstName] AS [FirstName],
[c].[LastName] AS [LastName],
[c].[HomePhone] AS [HomePhone],
[c].[WorkPhone] AS [WorkPhone],
[c].[MobilePhone] AS [MobilePhone],
[c].[Email] AS [Email],
[c].[Fax] AS [Fax]
FROM (SELECT
[Person].[FirstName] AS [FirstName],
[Person].[LastName] AS [LastName],
[Person].[HomePhone] AS [HomePhone],
[Person].[WorkPhone] AS [WorkPhone],
[Person].[MobilePhone] AS [MobilePhone],
[Person].[Email] AS [Email],
[Person].[Fax] AS [Fax],
[Person].[ValidFromDate] AS [ValidFromDate],
[Person].[ValidToDate] AS [ValidToDate],
[Person].[LastPulled] AS [LastPulled],
[Person].[IsCurrent] AS [IsCurrent]
FROM [dbo].[Person] AS [Person]) AS [c]
As you can see there is an inner-query which contains the additional columns.
At this point I'm kind of stumped as to why this is happening. How do I remove these columns from both sides of the mapping, or otherwise stop EF from putting unwanted columns in ANY part of the query?
When you use the EDMX designer and simply delete a column from an entity - this does not fully remove the column from the EDMX. Assuming you truly want it gone, you can open the EDMX file with a text editor and remove it by hand. To make sure that your manual changes trigger a rebuild of your auto-generated classes, edit it in Visual Studio and you shouldn't have an issue.
Right-click the EDMX in solution explorer
Open With...
XML (Text) Editor
I would expect if you were to open the EDMX, you would find something that looks like:
<EntityType Name="Person">
<Property Name="FirstName" Type="varchar" />
<Property Name="LastName" Type="varchar" />
<Property Name="HomePhone" Type="varchar" />
<Property Name="WorkPhone" Type="varchar" />
<Property Name="MobilePhone" Type="varchar" />
<Property Name="Email" Type="varchar" />
<Property Name="Fax" Type="varchar" />
<Property Name="ValidFromDate" Type="datetime" />
<Property Name="ValidToDate" Type="datetime" />
<Property Name="LastPulled" Type="datetime" />
<Property Name="IsCurrent" Type="short" />
</EntityType>
And you would just remove the bottom 4 columns, save and close, and rebuild the project.
EDIT: In case anyone in the future references this answer, if you do not first delete the column in the designer (like the OP did in this case), there will be two other instances of the column(s) in the XML that you would also need to remove in order for it to compile.
Thanks to #Borophyll for pointing me in roughly the right direction. Although their answer was not the solution to my issue, it did allow me to see the actual issue.
in the EDMX file there is also a entry that looks like this:
<EntitySet Name="Person" EntityType="Self.Person" store:Type="Tables" store:Schema="dbo">
<DefiningQuery>SELECT
[Person].[FirstName] AS [FirstName],
[Person].[LastName] AS [LastName],
[Person].[HomePhone] AS [HomePhone],
[Person].[WorkPhone] AS [WorkPhone],
[Person].[MobilePhone] AS [MobilePhone],
[Person].[Email] AS [Email],
[Person].[Fax] AS [Fax],
[Person].[ValidFromDate] AS [ValidFromDate],
[Person].[ValidToDate] AS [ValidToDate],
[Person].[LastPulled] AS [LastPulled],
[Person].[IsCurrent] AS [IsCurrent]
FROM [dbo].[Person] AS [Person]</DefiningQuery>
</EntitySet>
And that's where the weird sub-query was coming. I think the reason is that the table has no primary key as it is part of a staging database.
I just deleted from the SELECT statement the last four columns and everything worked.
Is it possible to add a property inside a new aspect that will hold a User from Alfresco's users ?
It will be used to input the User who's responsabile/authorizer of a document having a defined aspect.
The problem is that you've defined the same field twice. First as a d:text property and the second is an association.
In your model you've defined
<property name="txm:vacationPerson">
<title>Nom et prénom</title>
<type>d:text</type>
</property>
And as association you've defined:
<associations>
<association name="txm:vacationPerson">
<title>Assignee</title>
<source>
<mandatory>false</mandatory>
<many>false</many>
</source>
<target>
<class>cm:person</class>
<mandatory>false</mandatory>
<many>false</many>
</target>
</association>
</associations>
So it's rendering the first field as text and the second field isn't rendered anymore.
Remove the first d:text property or rename it.
Yes, and you may choose to use either an assocation or a property. Assuming you want users to pick the person manually, I'd go for the association since the default controls provided by share support picking a person out of the box.
Here is a sample aspect showing both - a property and an association to hold the user.
<aspect name="your:assignee">
<title>Your Aspect</title>
<properties>
<property name="your:assigedPersonUsername">
<title>Owner</title>
<type>d:text</type>
</property>
</properties>
<associations>
<association name="your:assignedPerson">
<title>Assignee</title>
<source>
<mandatory>false</mandatory>
<many>false</many>
</source>
<target>
<class>cm:person</class>
<mandatory>false</mandatory>
<many>false</many>
</target>
</association>
</associations>
</aspect>
I have a master report with 2 subreports. I use the same report to generate PDF and xls. Pagination is enabled but for excel, i need to disable pagination, which i do by rendering all in one sheet. The page header/column header get repeat for each page. These page header/column header are from the sub reports. This is fine for PDF but in case of excel, i want to get rid of the repeating header.
I set these properties:
<property name="net.sf.jasperreports.export.xls.exclude.origin.band.3" value="pageHeader" />
<property name="net.sf.jasperreports.export.xls.exclude.origin.keep.first.band.3" value="pageHeader" />
<property name="net.sf.jasperreports.export.pdf.exclude.origin.keep.first.band.1" value="pageHeader" />
<property name="net.sf.jasperreports.export.xls.exclude.origin.band.1" value="columnHeader" />
<property name="net.sf.jasperreports.export.xls.exclude.origin.keep.first.band.1" value="columnHeader" />
<property name="net.sf.jasperreports.export.xls.exclude.origin.band.2" value="pageFooter" />
<property name="net.sf.jasperreports.export.xls.remove.empty.space.between.rows" value="true" />
<property name="net.sf.jasperreports.export.xls.remove.empty.space.between.columns" value="true" />
But these arent reflected in the data rendered by the subreport. In xls, i still see the pageHeader/columnHeader gets repeated. Please let me know, how to fix this.
For XLS (and HTML) reports, you may want to set the parameter IS_IGNORE_PAGINATION to true. See http://jasperreports.sourceforge.net/api/net/sf/jasperreports/engine/JRParameter.html for documentation.
I know this is an old question, but I keep forgetting how to do this myself and each time I search I seem to find this question so thought I'd put something so I find it next time.
In the main report file you also need to add the sub report to the filter:
<property name="net.sf.jasperreports.export.xls.exclude.origin.band.1" value="columnHeader" />
<property name="net.sf.jasperreports.export.xls.exclude.origin.keep.first.band.1" value="columnHeader" />
<property name="net.sf.jasperreports.export.xls.exclude.origin.report.1" value="sub-report-name" />
<property name="net.sf.jasperreports.export.xls.exclude.origin.keep.first.report.1" value="sub-report-name" />
I want to manage a table with a VARCHAR primary key, that in the
mapped java object should be a UUID.
i have my sql-map-config.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<properties resource="database.properties"/>
<typeHandlers>
<typeHandler
handler="[...].persistence.typehandlers.UuidTypeHandler"
javaType="java.util.UUID"
jdbcType="VARCHAR"/>
</typeHandlers>
<environments default="development">
<environment id="development">
<transactionManager type="JDBC" />
<dataSource type="POOLED">
<property name="driver" value="${driver}" />
<property name="url" value="${url}" />
<property name="username" value="${username}" />
<property name="password" value="${password}" />
</dataSource>
</environment>
</environments>
<mappers>
<mapper resource="user.xml" />
</mappers>
</configuration>
and the user.xml is like that:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="[...].persistence.mappers.UserMapper">
<select id="selectUserByUUID" parameterType="java.util.UUID"
resultMap="userResultMap">
SELECT * FROM user WHERE uuid = #{uuid, jdbcType=VARCHAR,
typeHandler=[...].persistence.typehandlers.UuidTypeHandler}
</select>
<resultMap id="userResultMap" type="[...].model.User">
<id property="uuid" column="uuid" jdbcType="OTHER"
typeHandler="[...].persistence.typehandlers.UuidTypeHandler"/>
...
</resultMap>
</mapper>
anyway, i got this exception:
org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause:
org.apache.ibatis.reflection.ReflectionException: There is no getter
for property named 'uuid' in 'class java.util.UUID'
### The error may involve
[...].persistence.mappers.UserMapper.selectUserByUUID-Inline
### The error occurred while setting parameters
### Cause: org.apache.ibatis.reflection.ReflectionException: There is
no getter for property named 'uuid' in 'class java.util.UUID'
it seems that my typehandler never gets called (i have it logging a
bit, but never prints anything).
Is there something wrong? Thanks.
Your problem is right there in your exception....
There is no getter for property named 'uuid' in 'class java.util.UUID'
Use a parameter type of String, and pass in unique id as an argument. You don't need a type handler.
Seems kinda odd answering my own question, but i got some help on the mybatis-users list, so i'd like to share some hints here:
Mybatis was trying to "get" a non-existing field:
Luckily, one of mybatis developers helped me a while ago, suggesting that the easiest way to get it to work was to add a #Param annotation in the UserMapper to do this thing:
public User selectUserByUUID(#Param("uuid") UUID uuid);
<select id="selectUserByUUID" parameterType="uuid" resultMap="userResultMap">
SELECT * FROM user WHERE uuid = #{uuid, typeHandler=com.collective.persistence.typehandlers.UuidTypeHandler, javaType=uuid, jdbcType=VARCHAR}
</select>
I was stuck in watching the typehandler configuration, but,
if I understood it right, this has not much to do with typehandlers,
since they are used to "transport and translate" data between the sql
table and the java objects (through setter and getters), while my
issue was in the handling of methods' parameters. Hope this helps someone.
Also such error could be fixed by adding in mapper file new method with corresponding queue
Smth like this:
#Select("SELECT * FROM Users u WHERE u.userUUID = '${uuid}'")
User selectByUserUuid(#Param("uuid") UUID uuid);