Following the quickstart on liquibase i've created a changeset (very dumb :) )
Code:
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog/1.6"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog/1.6
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-1.6.xsd">
<changeSet id="1" author="me">
<createTable tableName="first_table">
<column name="id" type="int">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="name" type="varchar(50)">
<constraints nullable="false"/>
</column>
</createTable>
<createTable tableName="new_table">
<column name="id" type="int">
<constraints primaryKey="true" nullable="false"/>
</column>
</createTable>
</changeSet>
</databaseChangeLog>
I've created a clean schema and i've launched the migrate command.
Liquibase created the database, with the support tables databasechangelog and ..lock.
Now how i can track the changes?? i've modified the changeset adding a new createTable element but when i try the command "update" liquibase tells me this
Migration Failed: Validation Failed:
1 change sets check sum
so i don't think to have understood the way to work with liquibase.
Someone may point me to the right direction??
Thanks
You should never modify a <changeSet> that was already executed. Liquibase calculates checksums for all executed changeSets and stores them in the log. It will then recalculate that checksum, compare it to the stored ones and fail the next time you run it if the checksums differ.
What you need to do instead is to add another <changeSet> and put your new createTable element in it.
QuickStart is good readin' but it is indeed quick :-) Check out the full manual, particularly its ChangeSet section.
This currently accepted answer is slightly out of date based on changes in Liquibase 2.x. In the 2.x version, Liquibase will still fail if the md5 checksum has changed for a changeset, but you can specify the runOnChange attribute if you want to be able modify it.
From the documentation:
runOnChange - Executes the change the first time it is seen and each time the change set has been changed
If it's a change to a changeset that basically has already been done, you can manually modify the database so that its md5 for that changeset matches the new one. Good for minor textual changes. Or you can delete that changeset row from your table.
Related
A quick one, I am looking for a tool for data generation. I have an entity with dates; the date it was made, a start date and an end date. I want the data generation to take care of this constraints:
made maybe today or some day after
start maybe equal to made but not before
end maybe only be a day after start or any other date after start
I looked at http://generatedata.com and http://mockaroo.com, but they didn't have a way i could maintain the constraints. I just need that constraint, but not sure which softwares to try to maintain these constraints. I just need quick data to test my application. thanks
and just a by and by, have you ever been in such a situation where what you need you can't find?
benerator is the tool to use, which is is very flexible though one needs to learn it pretty fast. with my above situation, in the xml file for benerator (that's what it uses ), i just write the following and i'm good to go. in fact, i can even now put ranges for made, start and end dates. This is a section of a generate tag for 30 records of an entity (let's call it MY_ENTITY) with those dates
<import class="org.databene.commons.TimeUtil"/>
<generate name="MY_ENTITY" count="30" consumer="ENTITY_OUT">
<attribute name="MADE_DATE" type="date" script ="TimeUtil.today()" />
<variable name= "for_startDate" type="int" min="0" max="10" />
<attribute name="START_DATE" type="date" script="TimeUtil.addDays(this.MADE_DATE,
for_startDate)" nullable="false"/>
<variable name="for_endDate" type="int" min="1" max="10" />
<attribute name="END_DATE" type = "date" script="TimeUtil.addDays(this.START_DATE,
for_endDate)" nullable="false"/>
</generate>
and benerator supports many databases through JDBC, and it comes loaded with several JDBC drivers. try it here http://bergmann-it.de/test-software/index.php?lang=en. it's open source
I've found a few related solutions to this problem. The related solutions will not work for me as I'll explain. (I'm using Solr 4.0 and indexing data stored in an Oracle 11g database.)
Jonck van der Kogel's related solution (from 2009) is explained here. He describes creating a custom Transformer, sort of like the ClobTransformer that ships with Solr. This is going down the elegant path but is not using Tika which is now integrated with Solr. (He uses external PDFBox and FontBox.) This creates multiple maintenance / upgrade dependencies. Also, I need to be able to index Word documents in addition to PDF.
Since Kogel's solutions seems to be on the right path, is there a way to use the Tika classes included with Solr in a custom Transformer? That would allow all the Tika functionality with Kogel's elegant database solution.
Another related solution is the ExtractingRequestHandler (ERH) that ships with Solr. However, as the name suggests, this is a request handler, such as to handle HTTP posts of rich-text documents. To extract documents from the database this way has performance and security problems. I would have to make the database BLOBs accessible via HTTP. I've found no discussion of using ERH for direct ingest from a database BLOB. Is it possible to directly ingest from database BLOBs with Solr Cell?
Another related solution is to write a Transformer (like Kogel's above) to convert a byte[] to a string (from DataImportHandler FAQ). With true binary documents this is going to feed junk into the index and not properly extract the text elements like Tika does. Won't work.
A final related solution is UpdateRichDocuments offered by the RichDocumentHandler. This is deprecated and no longer available in Solr. The page refers you to the ExtractingRequestHandler (discussed above).
It seems like the right solution is to use DataImportHandler and a customer Transformer using the Tika class. How does this work?
Many hours later... First, there is a lot of misleading, wrong and useless information on this problem. No page seemed to provide everything in one place. All of the information is well intentioned but between differing versions and some going over my head, it didn't solve the problem. Here is my collection of what I learned and the solution. To reiterate, I'm using Solr 4.0 (on Tomcat) + Oracle 11g.
Solution overview: DataImportHandler + TikaEntityProcessor + FieldStreamDataSource
Step 1, make sure you update your solrconfig.xml so that solr can find the TikaEntityProcessor + DataImportHandler + Solr Cell stuff.
<lib dir="../contrib/dataimporthandler/lib" regex=".*\.jar" />
<!-- will include extras (where TikaEntPro is) and regular DIH -->
<lib dir="../dist/" regex="apache-solr-dataimporthandler-.*\.jar" />
<lib dir="../contrib/extraction/lib" regex=".*\.jar" />
<lib dir="../dist/" regex="apache-solr-cell-\d.*\.jar" />
Step 2, modify your data-config.xml to include your BLOB table. This is where I had the most trouble since the solutions to this problems have changed a lot as versions have changed. Plus, using multiple data sources and plugging them together correctly was not intuitive to me. Very sleek once it's done though. Make sure to replace your IP, SID name, username, password, table names, etc.
<dataConfig>
<dataSource name="dastream" type="FieldStreamDataSource" />
<dataSource name="db" type="JdbcDataSource"
driver="oracle.jdbc.OracleDriver"
url="jdbc:oracle:thin:#192.1.1.1:1521:sid"
user="username"
password="password"/>
<document>
<entity
name="attachments"
query="select * from schema.attachment_table"
dataSource="db">
<entity
name="attachment"
dataSource="dastream"
processor="TikaEntityProcessor"
url="blob_column"
dataField="attachments.BLOB_COLUMN"
format="text">
<field column="text" name="body" />
</entity>
</entity>
<entity name="unrelated" query="select * from another_table" dataSource="db">
</entity>
</document>
</dataConfig>
Important note here. If you're getting "No field available for name : whatever" errors when you attempt to import, the FieldStreamDataSource is not able to resolve the data field name you gave. For me, I had to have the url attribute with the lower-case column name, and then the dataField attribute with outside_entity_name.UPPERCASE_BLOB_COLUMN. Also, once I had the column name wrong and that will cause the problem as well.
Step 3, you need to modify your schema.xml to add the BLOB-column field (and any other column you need to index/store). Modify according to your needs.
<field name="body" type="text_en" indexed="false" stored="false" />
<field name="attach_desc" type="text_general" indexed="true" stored="true" />
<field name="text" type="text_en" indexed="true" stored="false" multiValued="true" />
<field name="content" type="text_general" indexed="false" stored="true" multiValued="true" />
<copyField source="body" dest="text" />
<copyField source="body" dest="content" />
With that you should be well on your way to saving many hours getting your binary, rich-text documents (aka rich documents) that are stored as BLOBs in a database column indexed with Solr.
The Integration of Tika and DIH is already provided with Solr via TikaEntityProcessor
Integration - SOLR-1358
Blob Handling - SOLR-1737
You need to just find the right combination.
i'm trying to use hibernate with an existing mysql db using Eclipse.
I've succeeded mapping tables to classes and executing some query.
But i have a problem with a one to many relation.
I have the table "CARATTERISTICHE" (attributes) which is, in fact, a tree, described by a join table "VALORI" (values): "fk_child" "fk_parent".
I would like that the class Caratteristica had a field "children" with type List<Caratteristica>, where the children should be the join with CARATTERISTICA and VALORI.
My first attempt was to create a pojo Caratteristica and let eclipse generate the configurations file of hibernate.
That doesn't work because when I launch getChildren all i got is the same object (i.e. every node is his father, which is false in my db).
This is an excerpt of the generated xml:
<class name="model.Caratteristica" table="caratteristiche">
<id name="id" type="java.lang.Integer">
<column name="ID"/>
<generator class="assigned"/>
</id>
<set access="field" lazy="true" name="children"
sort="unsorted" table="valori">
<key>
<column name="id"/>
</key>
<one-to-many class="model.Caratteristica"/>
</set>
Note that if change the column key from id to fk_child he can't find fk_child in table "CARATTERISTICHE" (but it should look in VALORI, right?)
I've also tried to generate pojos from tables but it's worse..
Maybe i've got this problem hibernate- composite key configuration but.. it's my first time I use hibernate, I'm really lost!
Your data model is a bit strange.
Either you have a complete tree structure, i. e. a 1 : n relation between parents and children. Then you do not need the join table VALORI. In CARATTERISTICHE you just define a column parentId, which contains the id of the parent row. In your mapping you give this new column as the key tag: <key> <column name="parentId"/> </key>
Or you have an m : n relation between parents and children, which is defined by the join table VALORI. The tree structure can be defined as a special case with the m : n relation, but other structures are also possible. Then you must use the <many-to-many> tag (instead of one-to-many). The <many-to-many> tag contains the column attribute, which allows to specify the name of the corresponding foreign key in the other table.
I'm trying to use microsoft's sample database AdventureWorks2008R2... when I try to create the ADO.NET entity data model I get this error:
Unable to generate the model because of the following exception: 'The table 'C:\USERS\XXXX\DOCUMENTS\VISUAL STUDIO 2010\PROJECTS\ANOTHERWORKS\ANOTHERWORKS\APP_DATA\ADVENTUREWORKS2008R2_DATA.MDF.Production.Document' was referenced by a relationship, but was not found.'.
Loading metadata from the database took 00:00:06.2308687.
Generating the model took 00:00:04.5808698.
Added the connection string to the Web.Config file.
Successfully registered the assembly 'System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' in the Web.Config file.
Writing the .edmx file took 00:00:00.0015898.
Anyone encountered and fixed this? Or knows somewhere I can download a working version of this database ( other then: http://msftdbprodsamples.codeplex.com/releases/view/59211 which is where I got it )
Or can someone point to a sample database I can download and use around with entity framework.
EDIT
The new EF designer (Beta 1 available here) will not try creating relationships to non-existing tables so instead of the error and empty model you will get a model where invalid entity types/sets and relationships are commented out.
**
I looked at it for AdventureWorks for Sql Server 2012 but I think it is the same thing you hit for 2008R2/
The issue here is that the Production.Document table has a key that is of HierarchyId type and EF currently does not support HierarchyId type. EF ignores columns of types it does not understand when creating the model however if it does not understand a key column it will exclude the entire entity from the model. For excluded entities you should be able to find them commented out in the model when you open it with an Xml/Text editor. In this particular case this is what will see:
<EntityContainer Name="AdventureWorksModelStoreContainer" />
<!--Errors Found During Generation:
warning 6005: The data type 'hierarchyid' is currently not supported for the target .NET Framework version; the column 'DocumentNode' in table 'AdventureWorks.Production.Document' was excluded.
warning 6031: The column 'DocumentNode' on the table/view 'AdventureWorks.Production.Document' was excluded, and is a key column. The table/view has been excluded. Please fix the entity in the schema file, and uncomment.
<EntityType Name="Document">
<Property Name="DocumentLevel" Type="smallint" StoreGeneratedPattern="Computed" />
<Property Name="Title" Type="nvarchar" Nullable="false" MaxLength="50" />
<Property Name="Owner" Type="int" Nullable="false" />
<Property Name="FolderFlag" Type="bit" Nullable="false" />
<Property Name="FileName" Type="nvarchar" Nullable="false" MaxLength="400" />
<Property Name="FileExtension" Type="nvarchar" Nullable="false" MaxLength="8" />
<Property Name="Revision" Type="nchar" Nullable="false" MaxLength="5" />
<Property Name="ChangeNumber" Type="int" Nullable="false" />
<Property Name="Status" Type="tinyint" Nullable="false" />
<Property Name="DocumentSummary" Type="nvarchar(max)" />
<Property Name="Document" Type="varbinary(max)" />
<Property Name="rowguid" Type="uniqueidentifier" Nullable="false" />
<Property Name="ModifiedDate" Type="datetime" Nullable="false" />
</EntityType>-->
</Schema>
Notice this warning:
warning 6031: The column 'DocumentNode' on the table/view 'AdventureWorks.Production.Document' was excluded, and is a key column. The table/view has been excluded. Please fix the entity in the schema file, and uncomment.
Now in the AdventureWorks database the Production.Document table is referenced by Production.ProductDocument table. Since no entity for Production.Document table was created EF is unable to create the reference from Production.ProductDocument entity and hence the "Production.Document' is referenced by a relationship, but cannot be found.' error.
Since the Production.Document table cannot be really used "as is" by EF the easiest workaround is to exclude this entity when generating the model from entity - check all tables but Production.Document in the wizard and you should be good to go. EF will ignore all references to this entity since you excluded it and therefore there should be no error.
Link to a related work item on Entity Framework codeplex site
Sql Server 2008 R2 Express. NHibernate 2.1.2.4.
I get SQL like:
SELECT customer0_.Id as Id1_0_
FROM customers customer0_
WHERE customer0_.Id=#p0;
#p0 = 11111111-1111-1111-1111-111111111111
...which returns 0 records even though there is Customer in there with that Id.
The SQL Server column datatype is UNIQUEIDENTIFIER.
<session-factory> configured as follows:
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
Class's <id> configured as follows
<id name="_id" column="Id" type="Guid" access="field" unsaved-value="00000000-0000-0000-0000-000000000000" >
<generator class="guid.comb" />
</id>
Forging my way through this for the first time, w/ the help of various tuts. I've been over everything several times but no joy. Any ideas what is wrong/missing here? TYIA!
This seems correct. According to this "we must remember that a Guid is not a string even thought that's how we see them. A Guid is a 16-byte data structure." So I'm not sure why you are not getting back the results you expect, but I think the generated SQL is correct in not having the quotes.