Redian新闻
>
return type, map or object
avatar
return type, map or object# Java - 爪哇娇娃
D*e
1
刑警803死活从电驴上下不下来啊
NND
avatar
c*t
2
Can any nHibernate expert let me know what's wrong with the following? I
alwasy got Acccount.ListAttr as null; when do "foreach(var a in Account.
ListAttr)" I got invalid cast error: can't cast ISet to IList..
I have Account.hbm.xml as follows:
...




..
and Account.cs has:
public virtual ISet ListAttr {get; set; }
..
Also have SomeOtherClass.hbm.xml:
...









select Col1, Col2 from SomeTable where attr=?

and SomeOtherClass.cs
public virtual String Col1 {get; set; }
public virtual String Col2 {get; set; }
public virtual int SomeId {get; set; }
..
avatar
P*P
3
在写一个class,要return三个参数,我现在是把三个参数放到map里,然后return map.不
知道这样做好不好?还是我应该把三个参数做成object,然后return那个object?
avatar
c*t
4
其实就是根据Account table中的一个field去query一组tables得到一组数据: ISet<
CustomClass> ListAttr。
avatar
k*r
5
map needs a lot of memory. a simple class is cheap :)

【在 P*P 的大作中提到】
: 在写一个class,要return三个参数,我现在是把三个参数放到map里,然后return map.不
: 知道这样做好不好?还是我应该把三个参数做成object,然后return那个object?

avatar
s*o
6
if you are using .NET 4, then there are two ISet available.
One is from System.Collections.Generic, and the other is from Iesi.
Collections.Generic. Maybe there is a type mismatch here?
avatar
P*P
7
多谢.
三个参数是string, long and boolean. 或者我把三个参数concatenate成一个string,
用的时候再分解?

【在 k***r 的大作中提到】
: map needs a lot of memory. a simple class is cheap :)
avatar
c*t
8
I use .NET 3.5.
avatar
l*u
9
i vot 4 object

【在 P*P 的大作中提到】
: 在写一个class,要return三个参数,我现在是把三个参数放到map里,然后return map.不
: 知道这样做好不好?还是我应该把三个参数做成object,然后return那个object?

avatar
c*t
10
using profile, I figured what went wrong. I have Account.hbm.xml as


...
The issue was nHibernate always passes in "Account_Id" for my sql-query...
it's not SomeId.
avatar
g*g
11
Martin Fowler will 2nd that.

【在 l****u 的大作中提到】
: i vot 4 object
avatar
c*t
12
It's mapping issue:
WARN:
System.IndexOutOfRangeException: Unable to find specified column in result
set
at Oracle.DataAccess.Client.OracleDataReader.GetOrdinal(String name)
at NHibernate.Type.NullableType.NullSafeGet(IDataReader rs, String name)
at NHibernate.Type.NullableType.NullSafeGet(IDataReader rs, String[]
names, ISessionImplementor session, Object owner)
at NHibernate.Type.ManyToOneType.Hydrate(IDataReader rs, String[] names,
ISessionImplementor session, Object owner)
at NHibernate.Persister.Entity.AbstractEntityPersister.Hydrate(
IDataReader rs, Object id, Object obj, ILoadable rootLoadable, String[][]
suffixedPropertyColumns, Boolean allProperties, ISessionImplementor session)
at NHibernate.Loader.Loader.LoadFromResultSet(IDataReader rs, Int32 i,
Object obj, String instanceClass, EntityKey key, LockMode lockMode,
ILoadable rootPersister, ISessionImplementor session)
at NHibernate.Loader.Loader.InstanceNotYetLoaded(IDataReader dr, Int32 i,
ILoadable persister, EntityKey key, LockMode lockMode, EntityKey
optionalObjectKey, Object optionalObject, IList hydratedObjects,
ISessionImplementor session)
at NHibernate.Loader.Loader.GetRow(IDataReader rs, ILoadable[] persisters
, EntityKey[] keys, Object optionalObject, EntityKey optionalObjectKey,
LockMode[] lockModes, IList hydratedObjects, ISessionImplementor session)
at NHibernate.Loader.Loader.GetRowFromResultSet(IDataReader resultSet,
ISessionImplementor session, QueryParameters queryParameters, LockMode[]
lockModeArray, EntityKey optionalObjectKey, IList hydratedObjects, EntityKey
[] keys, Boolean returnProxies)
at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session,
QueryParameters queryParameters, Boolean returnProxies)
at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(
ISessionImplementor session, QueryParameters queryParameters, Boolean
returnProxies)
at NHibernate.Loader.Loader.DoList(ISessionImplementor session,
QueryParameters queryParameters)
avatar
S*t
13
who is martin

【在 g*****g 的大作中提到】
: Martin Fowler will 2nd that.
avatar
l*u
14
a java highhand, google his name, u will see...

【在 S*********t 的大作中提到】
: who is martin
avatar
l*u
15
define an object would be much easier for maintain,
easy to understand.
also easy to unit test.

string,

【在 P*P 的大作中提到】
: 多谢.
: 三个参数是string, long and boolean. 或者我把三个参数concatenate成一个string,
: 用的时候再分解?

avatar
k*r
16
No. Just define an inner class. new it, and return it.

string,

【在 P*P 的大作中提到】
: 多谢.
: 三个参数是string, long and boolean. 或者我把三个参数concatenate成一个string,
: 用的时候再分解?

avatar
c*g
17
store them into a vector and return it.
avatar
Z*e
18
never liked the idea of storing heterogeneous data in a vector, or
collections alike

【在 c********g 的大作中提到】
: store them into a vector and return it.
avatar
S*t
19
agree.
not a good idea using vector.
also not fancy inner class idea.

【在 Z****e 的大作中提到】
: never liked the idea of storing heterogeneous data in a vector, or
: collections alike

avatar
g*g
20
It depends on how the data object is coupled with the function class.
If the data doesn't make sense out of functional class context,
using inner class is a good pattern.

【在 S*********t 的大作中提到】
: agree.
: not a good idea using vector.
: also not fancy inner class idea.

avatar
h*j
21
of coz type

【在 P*P 的大作中提到】
: 在写一个class,要return三个参数,我现在是把三个参数放到map里,然后return map.不
: 知道这样做好不好?还是我应该把三个参数做成object,然后return那个object?

avatar
F*n
22
Using Map is not uncommon. You can use LinkedHashMap for small number of
objects.

【在 Z****e 的大作中提到】
: never liked the idea of storing heterogeneous data in a vector, or
: collections alike

avatar
b*y
23
object is better, it is easier to see what's returned.
avatar
k*r
24
maps has poorer memory efficiency. java is already bad in terms of memory usage. Don't
make it worse :)
avatar
I*o
25
can u describe what does this method (class?????) do?

【在 P*P 的大作中提到】
: 在写一个class,要return三个参数,我现在是把三个参数放到map里,然后return map.不
: 知道这样做好不好?还是我应该把三个参数做成object,然后return那个object?

avatar
n*8
26
sounds a method that return 3 types of parameters. Why do you not use 3
public unique class variables that you can access from anywhere?
avatar
t*e
27

Thread safety will be an issue if he follows your suggestion.
The question is about static data typing (a data object) or dynamic data
typing (a Map, or List, or Collection). Static typing is always preferred
unless the data types may evolve in the future upon business requirements.

【在 n******8 的大作中提到】
: sounds a method that return 3 types of parameters. Why do you not use 3
: public unique class variables that you can access from anywhere?

avatar
m*t
28

I don't know which part is scarier - "public" or "class".
I do like "unique" though. At least we are not going to
try and pad 3 parameters into one single string.

【在 n******8 的大作中提到】
: sounds a method that return 3 types of parameters. Why do you not use 3
: public unique class variables that you can access from anywhere?

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。