What is the best way trying to get a text search function using nhibernate? I have read about NHibernate.Search, but cannot find the library anywhere.
I downloaded the latest NHibernate source code(2.1.2) and compiled it, but i still cannot find NHibernate.Search.
Does anyone have any suggestions? Or any other methods to do text search?
EDIT: Using MySQL database, incase it makes any difference.
NHiberante.Search a separate dll to make Nhiberante and Lucene work together. You have to download and reference it if you want to use it. You might like to read some introduction about Lucene to understand how Nhiberante.Search works.
One of the places where you can get the dll is hornget
If you want to the MySql specific full text search options, there won't be any help from Nhibernate for you to use them.
You can use Expression.Sql but i think it's good idea using mysql stored procedure
Your MySql Stored Procedure :
CREATE PROCEDURE `GetProductsByText`(IN `queryText` VARCHAR(100) CHARSET utf8)
SELECT *
FROM Products
WHERE MATCH(Title, Description) AGAINST (queryText)
Your nhibernate mapping xml file :
<sql-query name="GetProductsByText">
<return class="Product"/>
call `GetProductsByText`( :queryText )
</sql-query>
your c# nhibernate query:
public IList<Product> FindByText (string text)
{
var session = SessionFactory.GetCurrentSession ();
IQuery query = session.GetNamedQuery ("GetProductsByText");
return query.SetString ("queryText", text).List<Product> ();
}
Related
So I have my location column using Point data type, I'm using Apollo Server and Prisma, and when I use "npx prisma db pull" generates this data type because is not currently supported on Prisma (generated script)
so I say "Ok, I'm using string and I manage how to insert this data type" so I changed to this script, surprise! didn't work enter image description here, try to find any approach to handling MySql Point data type in Prisma but no info at soever, I really appreciate any ideas
You cannot convert it to String and use it as it isn't supported yet. You need to leave it as unsupported and you can only add data via raw queries.
For now, only adding data is supported. You cannot query for it using PrismaClient.
We can query data using Prisma Client, via raw queries as SELECT id, ST_AsText(geom) as geom from training_data where geom has dataType geometry for using Unsupported("geometry").
I have a process in php like...
if (mb_detect_encoding($msg) == 'ASCII') {
....
} else {
....
}
Now, the above functionality I have to enable in mysql procedure. Is there any function or work around to achieve in mysql.
In other simple word mb_detect_encoding() equivalent in mysql !
Please help. Thanks.
There is no such functionality in mysql and I'm not even sure that you should have such functionality in adatabase either. Columns storing text have their fixed character set in mysql. It is the responsibility of the application using the database to ensure that text with right encoding is entered into the database.
EDIT:
Obviously, nothing prevents you from implementing a similar functionality using UDFs if you really insist on having this functionality within mysql.
Yes, of course, I know, there are many different generators created on Javascipt, php, etc. and even applications and web-services that allow generating sql.
But I’d like to have sql functions library which can be used during generating data right away from MySQL script and stored procedures.
Now I'm creating my own helper functions (and it’s quite tedious) that work roughly like bellow:
(fl_* - are functions that return fake data of corresponding type and features.)
-- create a fake user:
call sp_user_add(fl_login(), fl_email(), fl_gender(), #user_id);
-- add a fake post:
call sp_post_add(#user_id, fl_title(true, 1, 10), fl_body(true, 3, 20), #post_id);
You need to know mysql random data generator stored procedure.
See http://www.generatedata.com/. Here you can select the SQL-Tab and select the number of rows you want to get created. The result is a SQL-script you can copy-paste. I found this very handy...
I'm working with EntityFramework 5.0 and MySql. I have generated model from database, and my application now have to connect on multiple database with same structred data.
So i have to dynamic change connection string based on some info.
I try to change database name even from config section of connection string, and with EntityConnectionStringBuilder, but i had the same result: my new connection is stored correctly, but data returned are of the first database.
From WebConfig:
add name="dbIncassiEntities" connectionString="metadata=res:///DAL.Modelincassi.csdl|res:///DAL.Modelincassi.ssdl|res://*/DAL.Modelincassi.msl;provider=Devart.Data.MySql;provider connection string="user id=root ... database=dbname2"" providerName="System.Data.EntityClient" />
From code:
EntityConnectionStringBuilder entityBuilder = new EntityConnectionStringBuilder();
entityBuilder.Provider = providerName;
entityBuilder.ProviderConnectionString = "user id=...database=dbname2";
entityBuilder.Metadata = #"res://*/DAL.Modelincassi.csdl|res://*/DAL.Modelincassi.ssdl|res://*/DAL.Modelincassi.msl";
var context = new dbIncassiEntities(entityBuilder.ToString());
My constructor:
public dbIncassiEntities(string conn)
: base(conn)
{
}
What am i missing?
UPDATE
I can see that calling a query directly from SqlQuery, results returned are correct,
while using the generated entities i retrieve wrong data.
var test = context.Database.SqlQuery<string>(
"SELECT cognomenome FROM addetto limit 0,1").ToList();
But calling..
var oAddetto = from c in context.addettoes select c;
So my problem is only on the model itsself, and manually changing the generated schema
<EntitySet Name="addetto" EntityType="dbIncassiModel.Store.addetto" store:Type="Tables" Schema="dbname2" />
..i'll get the right information.
My question now is: how can i change in code these informations??
Any help is really appreciated!!
Thanks, David
Ok, i've found a workaround for now.
I simply clear the shema name on the designer, and now i can call the generated entities succesfully. Hope this can help anyone else.
David
While I could not remove the Schema in the designer, I removed it directly in the .edmx file. Do a full text search for Schema="YourSchema" in an XML editor of your choice and remove the entries. After that, changing the connection string is enough.
Downside is, the Visual Studio designer and mapping explorer won't work properly anymore.
This seems to be more of a dotConnect issue rather than MySQL, since the problem also exists for the Oracle adapter:
http://forums.devart.com/viewtopic.php?t=17427
There are a lot of examples over the net which describe how to call a stored procedure using Hibernate, however, when using Spring, the picture changes a bit.
I have a stored procedure in MySQL which I want to call:
in SQL I need to write the following:
CALL inrange(32.342324,32.234234);
It returns a row with the following: `{INT},{INT},{FLOAT}`
With Spring, I use the HibernateTemplate way of executing hibernate operations, I know that some of you won't like it, but this is the how the project was when I started, and I'm not so eager changing it, maybe in the future...
Currently, I have the following code in Java, which tries to call the procedure:
List<Object[]> resultset = hibernateTemplate
.findByNamedQuery("inrange",
person.getAddress().getLatitude(),
person.getAddress().getLongitude());
When I run it, I get the following Hibernate exception:
org.springframework.orm.hibernate3.HibernateSystemException:
Named query not known: inrange;
I figured that this is happening duo the fact that I didn't declare the stored procedure in hibernate.
My question is:
how do I declare it ?
Is there a special way of declaring it in the Spring's application context file ?
You can call native sql queries within hibernate.
Look at this link:
http://www.mkyong.com/hibernate/how-to-call-store-procedure-in-hibernate/
Btw if you want to call stored procedures you could simply use a Spring JdbcTemplate.
Notice that an hibernate extension can fit to your needs:
http://www.hibernatespatial.org/
You're confusing Hibernate's named queries with MySQL's stored procedures.
If you want to call the MySQL stored proc, there is no benefit to doing so through Hibernate's API. I recommend you use Spring's JdbcTemplate to perform the query.
If you absolutely must use Hibernate, something like this should work:
SQLQuery query = hibernateTemplate.getCurrentSession()
.createSQLQuery("SELECT inrange(:latitude, :longitude)";
query.setDouble("latitude", ...);
query.setDouble("longitude", ...);
List<Object[]> result = query.list(); // requires casting for generics
You need to add the named query to your hibernate mapping file.
Can you share your hibernate mapping file? You can find some samples here.
Along with the previous link you can go through this also.
It will be easier if you can share the POJO, hibernate mapping and the procedure you are using.
This blog will be of help for you. I hope you will not have any problem with using the getHibernateTemplate().execute(HibernateCallback) method.
You can use JPA as Spring supports it either in Core or Spring Data.
Calling the stored procedure can be done using the StoredProcedureQuery as follows:
StoredProcedureQuery query = entityManager
.createStoredProcedureQuery("count_comments")
.registerStoredProcedureParameter(
"postId", Long.class, ParameterMode.IN)
.registerStoredProcedureParameter(
"commentCount", Long.class, ParameterMode.OUT)
.setParameter("postId", 1L);
query.execute();
Long commentCount = (Long) query
.getOutputParameterValue("commentCount");